on 18574cd help sign in
rel8/src/Rel8/Type/Semigroup.hs
87 lines 2.2 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language FlexibleInstances #-}
4{-# language ScopedTypeVariables #-}
5{-# language StandaloneKindSignatures #-}
6{-# language TypeApplications #-}
7{-# language TypeFamilies #-}
8{-# language UndecidableInstances #-}
10module Rel8.Type.Semigroup
11 ( DBSemigroup( (<>.))
12 )
13where
15-- base
16import Data.Kind ( Constraint, Type )
17import Data.List.NonEmpty ( NonEmpty )
18import Prelude ()
20-- bytestring
21import Data.ByteString ( ByteString )
22import qualified Data.ByteString.Lazy as Lazy ( ByteString )
24-- case-insensitive
25import Data.CaseInsensitive ( CI )
27-- opaleye
28import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
30-- rel8
31import {-# SOURCE #-} Rel8.Expr ( Expr )
32import Rel8.Expr.Opaleye ( zipPrimExprsWith )
33import Rel8.Schema.Nullability ( Nullabilizes )
34import Rel8.Type ( DBType )
36-- text
37import Data.Text ( Text )
38import qualified Data.Text.Lazy as Lazy ( Text )
40-- time
41import Data.Time.Clock ( DiffTime, NominalDiffTime )
44type DBSemigroup :: Type -> Constraint
45class DBType a => DBSemigroup a where
46 (<>.) :: Expr a -> Expr a -> Expr a
47 infixr 6 <>.
50instance (DBType db, Nullabilizes db a) => DBSemigroup [a] where
51 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
54instance (DBType db, Nullabilizes db a) => DBSemigroup (NonEmpty a) where
55 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
58instance DBSemigroup DiffTime where
59 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:+))
62instance DBSemigroup NominalDiffTime where
63 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:+))
66instance DBSemigroup Text where
67 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
70instance DBSemigroup Lazy.Text where
71 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
74instance DBSemigroup (CI Text) where
75 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
78instance DBSemigroup (CI Lazy.Text) where
79 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
82instance DBSemigroup ByteString where
83 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
86instance DBSemigroup Lazy.ByteString where
87 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))