on fb4e1a5 help sign in
rel8/src/Rel8/Type/Monoid.hs
86 lines 2.0 kB history raw
1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
3{-# language FlexibleInstances #-}
4{-# language MultiParamTypeClasses #-}
5{-# language OverloadedStrings #-}
6{-# language StandaloneKindSignatures #-}
7{-# language TypeFamilies #-}
8{-# language UndecidableInstances #-}
10module Rel8.Type.Monoid
11 ( DBMonoid( memptyExpr )
12 )
13where
15-- base
16import Data.Kind ( Constraint, Type )
17import Prelude hiding ( null )
19-- bytestring
20import Data.ByteString ( ByteString )
21import qualified Data.ByteString.Lazy as Lazy ( ByteString )
23-- case-insensitive
24import Data.CaseInsensitive ( CI )
26-- rel8
27import {-# SOURCE #-} Rel8.Expr ( Expr )
28import Rel8.Expr.Array ( sempty )
29import Rel8.Expr.Serialize ( litExpr )
30import Rel8.Schema.Nullability
31 ( Unnullify
32 , Sql, HasNullability, nullabilization
33 )
34import Rel8.Type ( DBType, typeInformation )
35import Rel8.Type.Semigroup ( DBSemigroup )
37-- text
38import Data.Text ( Text )
39import qualified Data.Text.Lazy as Lazy ( Text )
41-- time
42import Data.Time.LocalTime ( CalendarDiffTime( CalendarDiffTime ) )
45-- | The class of 'Rel8.DBType's that form a semigroup. This class is purely a
46-- Rel8 concept, and exists to mirror the 'Monoid' class.
47type DBMonoid :: Type -> Constraint
48class DBSemigroup a => DBMonoid a where
49 -- The identity for '<>.'
50 memptyExpr :: Expr a
53instance Sql DBType a => DBMonoid [a] where
54 memptyExpr = sempty nullabilization typeInformation
57instance DBMonoid CalendarDiffTime where
58 memptyExpr = litExpr (CalendarDiffTime 0 0)
61instance DBMonoid Text where
62 memptyExpr = litExpr ""
65instance DBMonoid Lazy.Text where
66 memptyExpr = litExpr ""
69instance DBMonoid (CI Text) where
70 memptyExpr = litExpr ""
73instance DBMonoid (CI Lazy.Text) where
74 memptyExpr = litExpr ""
77instance DBMonoid ByteString where
78 memptyExpr = litExpr ""
81instance DBMonoid Lazy.ByteString where
82 memptyExpr = litExpr ""
85instance {-# INCOHERENT #-} (HasNullability a, DBMonoid (Unnullify a)) =>
86 Sql DBMonoid a