on eba6b2e help sign in
rel8/src/Rel8/Type/Semigroup.hs
90 lines 2.3 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 ( Sql )
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 )
44-- | The class of 'DBType's that form a semigroup. This class is purely a Rel8
45-- concept, and exists to mirror the 'Semigroup' class.
46type DBSemigroup :: Type -> Constraint
47class DBType a => DBSemigroup a where
48 -- | An associative operation.
49 (<>.) :: Expr a -> Expr a -> Expr a
50 infixr 6 <>.
53instance Sql DBType a => DBSemigroup [a] where
54 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
57instance Sql DBType a => DBSemigroup (NonEmpty a) where
58 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
61instance DBSemigroup DiffTime where
62 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:+))
65instance DBSemigroup NominalDiffTime where
66 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:+))
69instance DBSemigroup Text where
70 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
73instance DBSemigroup Lazy.Text where
74 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
77instance DBSemigroup (CI Text) where
78 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
81instance DBSemigroup (CI Lazy.Text) where
82 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
85instance DBSemigroup ByteString where
86 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
89instance DBSemigroup Lazy.ByteString where
90 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))