@@ -1,4 +1,5 @@
1{-# language DataKinds #-}
1{-# language DataKinds #-}
2+{-# language FlexibleContexts #-}
2{-# language ScopedTypeVariables #-}
3{-# language ScopedTypeVariables #-}
3{-# language TypeApplications #-}
4{-# language TypeApplications #-}
4{-# language TypeFamilies #-}
5{-# language TypeFamilies #-}
@@ -37,7 +38,7 @@ import Rel8.Expr.Opaleye
38import Rel8.Expr.Null ( null )
39import Rel8.Expr.Null ( null )
39import Rel8.Expr.Serialize ( litExpr )
40import Rel8.Expr.Serialize ( litExpr )
40−import Rel8.Schema.Nullability ( Nullability, Nullabilizes, nullabilization )
41+import Rel8.Schema.Nullability ( Nullability, Sql, nullabilization )
41import Rel8.Type.Array ( fromPrimArray )
42import Rel8.Type.Array ( fromPrimArray )
42import Rel8.Type.Eq ( DBEq )
43import Rel8.Type.Eq ( DBEq )
43import Rel8.Type.Num ( DBNum )
44import Rel8.Type.Num ( DBNum )
@@ -97,7 +98,7 @@ or = unsafeMakeAggregate toPrimExpr fromPrimExpr $
99-- | Produce an aggregation for @Expr a@ using the @max@ function.
100-- | Produce an aggregation for @Expr a@ using the @max@ function.
100−max :: (DBMax db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
101+max :: Sql DBMax a => Expr a -> Aggregate (Expr a)
101max = unsafeMakeAggregate toPrimExpr fromPrimExpr $
102max = unsafeMakeAggregate toPrimExpr fromPrimExpr $
102 Just Aggregator
103 Just Aggregator
103 { operation = Opaleye.AggrSum
104 { operation = Opaleye.AggrSum
@@ -107,7 +108,7 @@ max = unsafeMakeAggregate toPrimExpr fromPrimExpr $
109-- | Produce an aggregation for @Expr a@ using the @max@ function.
110-- | Produce an aggregation for @Expr a@ using the @max@ function.
110−min :: (DBMin db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
111+min :: Sql DBMin a => Expr a -> Aggregate (Expr a)
111min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
112min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
112 Just Aggregator
113 Just Aggregator
113 { operation = Opaleye.AggrSum
114 { operation = Opaleye.AggrSum
@@ -116,7 +117,7 @@ min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
118-- | Corresponds to @sum@.
119-- | Corresponds to @sum@.
119−sum :: (DBSum db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
120+sum :: Sql DBSum a => Expr a -> Aggregate (Expr a)
120sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
121sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
121 Just Aggregator
122 Just Aggregator
122 { operation = Opaleye.AggrSum
123 { operation = Opaleye.AggrSum
@@ -125,12 +126,12 @@ sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
128−sumWhere :: (DBNum db, DBSum db, Nullabilizes db a)
129+sumWhere :: (Sql DBNum a, Sql DBSum a)
129 => Expr Bool -> Expr a -> Aggregate (Expr a)
130 => Expr Bool -> Expr a -> Aggregate (Expr a)
130sumWhere condition a = sum (caseExpr [(condition, a)] 0)
131sumWhere condition a = sum (caseExpr [(condition, a)] 0)
133−stringAgg :: (DBString db, Nullabilizes db a)
134+stringAgg :: Sql DBString a
134 => Expr db -> Expr a -> Aggregate (Expr a)
135 => Expr db -> Expr a -> Aggregate (Expr a)
135stringAgg delimiter =
136stringAgg delimiter =
136 unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
137 unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
@@ -141,8 +142,8 @@ stringAgg delimiter =
144−-- | Aggregate a value by grouping by it.
145+-- | Aggregate a value by grouping by it.
145−groupByExpr :: (DBEq db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
146+groupByExpr :: Sql DBEq a => Expr a -> Aggregate (Expr a)
146groupByExpr = sgroupByExpr nullabilization
147groupByExpr = sgroupByExpr nullabilization