on ca7aaef help sign in
rel8/src/Rel8/Type/Semigroup.hs
91 lines 2.4 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language FlexibleInstances #-}
4{-# language MultiParamTypeClasses #-}
5{-# language ScopedTypeVariables #-}
6{-# language StandaloneKindSignatures #-}
7{-# language TypeApplications #-}
8{-# language TypeFamilies #-}
9{-# language UndecidableInstances #-}
11module Rel8.Type.Semigroup
12 ( DBSemigroup( (<>.))
13 )
14where
16-- base
17import Data.Kind ( Constraint, Type )
18import Data.List.NonEmpty ( NonEmpty )
19import Prelude ()
21-- bytestring
22import Data.ByteString ( ByteString )
23import qualified Data.ByteString.Lazy as Lazy ( ByteString )
25-- case-insensitive
26import Data.CaseInsensitive ( CI )
28-- opaleye
29import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
31-- rel8
32import {-# SOURCE #-} Rel8.Expr ( Expr )
33import Rel8.Expr.Opaleye ( zipPrimExprsWith )
34import Rel8.Schema.Nullability ( Unnullify, Sql, HasNullability )
35import Rel8.Type ( DBType )
37-- text
38import Data.Text ( Text )
39import qualified Data.Text.Lazy as Lazy ( Text )
41-- time
42import Data.Time.LocalTime ( CalendarDiffTime )
45-- | The class of 'DBType's that form a semigroup. This class is purely a Rel8
46-- concept, and exists to mirror the 'Semigroup' class.
47type DBSemigroup :: Type -> Constraint
48class DBType a => DBSemigroup a where
49 -- | An associative operation.
50 (<>.) :: Expr a -> Expr a -> Expr a
51 infixr 6 <>.
54instance Sql DBType a => DBSemigroup [a] where
55 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
58instance Sql DBType a => DBSemigroup (NonEmpty a) where
59 (<>.) = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:||))
62instance DBSemigroup CalendarDiffTime 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.:||))
90instance {-# INCOHERENT #-} (HasNullability a, DBSemigroup (Unnullify a)) =>
91 Sql DBSemigroup a