on fb3d2d9 help sign in
rel8/src/Rel8/Type/Semigroup.hs
85 lines 2.2 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language FlexibleInstances #-}
4{-# language MultiParamTypeClasses #-}
5{-# language StandaloneKindSignatures #-}
6{-# language TypeFamilies #-}
7{-# language UndecidableInstances #-}
9module Rel8.Type.Semigroup
10 ( DBSemigroup( (<>.))
11 )
12where
14-- base
15import Data.Kind ( Constraint, Type )
16import Data.List.NonEmpty ( NonEmpty )
17import Prelude ()
19-- bytestring
20import Data.ByteString ( ByteString )
21import qualified Data.ByteString.Lazy as Lazy ( ByteString )
23-- case-insensitive
24import Data.CaseInsensitive ( CI )
26-- opaleye
27import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
29-- rel8
30import {-# SOURCE #-} Rel8.Expr ( Expr )
31import Rel8.Expr.Opaleye ( zipPrimExprsWith )
32import Rel8.Schema.Null ( Sql )
33import Rel8.Type ( DBType )
35-- text
36import Data.Text ( Text )
37import qualified Data.Text.Lazy as Lazy ( Text )
39-- time
40import Data.Time.LocalTime ( CalendarDiffTime )
43-- | The class of 'Rel8.DBType's that form a semigroup. This class is purely a
44-- Rel8 concept, and exists to mirror the 'Semigroup' class.
45type DBSemigroup :: Type -> Constraint
46class DBType a => DBSemigroup a where
47 -- | An associative operation.
48 (<>.) :: Expr a -> Expr a -> Expr a
49 infixr 6 <>.
52instance Sql DBType a => DBSemigroup [a] where
53 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
56instance Sql DBType a => DBSemigroup (NonEmpty a) where
57 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
60instance DBSemigroup CalendarDiffTime where
61 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:+))
64instance DBSemigroup Text where
65 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
68instance DBSemigroup Lazy.Text where
69 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
72instance DBSemigroup (CI Text) where
73 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
76instance DBSemigroup (CI Lazy.Text) where
77 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
80instance DBSemigroup ByteString where
81 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
84instance DBSemigroup Lazy.ByteString where
85 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))