@@ -32,12 +32,13 @@ import Rel8.Expr.Bool ( caseExpr )
32import Rel8.Expr.Opaleye
32import Rel8.Expr.Opaleye
33 ( castExpr
33 ( castExpr
34 , fromPrimExpr
34 , fromPrimExpr
35− , unsafeFromPrimExpr
35+ , fromPrimExpr
36− , unsafeToPrimExpr
36+ , toPrimExpr
38import Rel8.Expr.Null ( null )
38import Rel8.Expr.Null ( null )
39import Rel8.Expr.Serialize ( litExpr )
39import Rel8.Expr.Serialize ( litExpr )
40import Rel8.Schema.Nullability ( Nullability, Nullabilizes, nullabilization )
40import Rel8.Schema.Nullability ( Nullability, Nullabilizes, nullabilization )
41+import Rel8.Type.Array ( fromPrimArray )
41import Rel8.Type.Eq ( DBEq )
42import Rel8.Type.Eq ( DBEq )
42import Rel8.Type.Num ( DBNum )
43import Rel8.Type.Num ( DBNum )
43import Rel8.Type.Ord ( DBMax, DBMin )
44import Rel8.Type.Ord ( DBMax, DBMin )
@@ -46,7 +47,7 @@ import Rel8.Type.Sum ( DBSum )
48count :: Expr a -> Aggregate (Expr Int64)
49count :: Expr a -> Aggregate (Expr Int64)
49−count = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
50+count = unsafeMakeAggregate toPrimExpr fromPrimExpr $
50 Just Aggregator
51 Just Aggregator
51 { operation = Opaleye.AggrCount
52 { operation = Opaleye.AggrCount
52 , ordering = []
53 , ordering = []
@@ -55,7 +56,7 @@ count = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
57countDistinct :: DBEq a => Expr a -> Aggregate (Expr Int64)
58countDistinct :: DBEq a => Expr a -> Aggregate (Expr Int64)
58−countDistinct = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
59+countDistinct = unsafeMakeAggregate toPrimExpr fromPrimExpr $
59 Just Aggregator
60 Just Aggregator
60 { operation = Opaleye.AggrCount
61 { operation = Opaleye.AggrCount
61 , ordering = []
62 , ordering = []
@@ -72,7 +73,7 @@ countWhere condition = count (caseExpr [(condition, litExpr (Just True))] null)
74and :: Expr Bool -> Aggregate (Expr Bool)
75and :: Expr Bool -> Aggregate (Expr Bool)
75−and = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
76+and = unsafeMakeAggregate toPrimExpr fromPrimExpr $
76 Just Aggregator
77 Just Aggregator
77 { operation = Opaleye.AggrBoolAnd
78 { operation = Opaleye.AggrBoolAnd
78 , ordering = []
79 , ordering = []
@@ -81,7 +82,7 @@ and = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
83or :: Expr Bool -> Aggregate (Expr Bool)
84or :: Expr Bool -> Aggregate (Expr Bool)
84−or = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
85+or = unsafeMakeAggregate toPrimExpr fromPrimExpr $
85 Just Aggregator
86 Just Aggregator
86 { operation = Opaleye.AggrBoolOr
87 { operation = Opaleye.AggrBoolOr
87 , ordering = []
88 , ordering = []
@@ -90,7 +91,7 @@ or = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
92max :: (DBMax db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
93max :: (DBMax db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
93−max = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
94+max = unsafeMakeAggregate toPrimExpr fromPrimExpr $
94 Just Aggregator
95 Just Aggregator
95 { operation = Opaleye.AggrSum
96 { operation = Opaleye.AggrSum
96 , ordering = []
97 , ordering = []
@@ -99,7 +100,7 @@ max = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
101min :: (DBMin db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
102min :: (DBMin db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
102−min = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
103+min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
103 Just Aggregator
104 Just Aggregator
104 { operation = Opaleye.AggrSum
105 { operation = Opaleye.AggrSum
105 , ordering = []
106 , ordering = []
@@ -108,7 +109,7 @@ min = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr $
110sum :: (DBSum db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
111sum :: (DBSum db, Nullabilizes db a) => Expr a -> Aggregate (Expr a)
111−sum = unsafeMakeAggregate unsafeToPrimExpr (castExpr . unsafeFromPrimExpr) $
112+sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
112 Just Aggregator
113 Just Aggregator
113 { operation = Opaleye.AggrSum
114 { operation = Opaleye.AggrSum
114 , ordering = []
115 , ordering = []
@@ -124,9 +125,9 @@ sumWhere condition a = sum (caseExpr [(condition, a)] 0)
124stringAgg :: (DBString db, Nullabilizes db a)
125stringAgg :: (DBString db, Nullabilizes db a)
125 => Expr db -> Expr a -> Aggregate (Expr a)
126 => Expr db -> Expr a -> Aggregate (Expr a)
126stringAgg delimiter =
127stringAgg delimiter =
127− unsafeMakeAggregate unsafeToPrimExpr (castExpr . unsafeFromPrimExpr) $
128+ unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
128 Just Aggregator
129 Just Aggregator
129− { operation = Opaleye.AggrStringAggr (unsafeToPrimExpr delimiter)
130+ { operation = Opaleye.AggrStringAggr (toPrimExpr delimiter)
130 , ordering = []
131 , ordering = []
131 , distinction = Opaleye.AggrAll
132 , distinction = Opaleye.AggrAll
@@ -137,22 +138,26 @@ groupByExpr = sgroupByExpr nullabilization
139listAggExpr :: Expr a -> Aggregate (Expr [a])
140listAggExpr :: Expr a -> Aggregate (Expr [a])
140−listAggExpr = unsafeMakeAggregate unsafeToPrimExpr fromPrimExpr $ Just
141+listAggExpr = unsafeMakeAggregate toPrimExpr from $ Just
141 Aggregator
142 Aggregator
142 { operation = Opaleye.AggrArr
143 { operation = Opaleye.AggrArr
143 , ordering = []
144 , ordering = []
144 , distinction = Opaleye.AggrAll
145 , distinction = Opaleye.AggrAll
148+ from = fromPrimExpr . fromPrimArray
148nonEmptyAggExpr :: Expr a -> Aggregate (Expr (NonEmpty a))
151nonEmptyAggExpr :: Expr a -> Aggregate (Expr (NonEmpty a))
149−nonEmptyAggExpr = unsafeMakeAggregate unsafeToPrimExpr fromPrimExpr $ Just
152+nonEmptyAggExpr = unsafeMakeAggregate toPrimExpr from $ Just
150 Aggregator
153 Aggregator
151 { operation = Opaleye.AggrArr
154 { operation = Opaleye.AggrArr
152 , ordering = []
155 , ordering = []
153 , distinction = Opaleye.AggrAll
156 , distinction = Opaleye.AggrAll
159+ from = fromPrimExpr . fromPrimArray
157sgroupByExpr :: DBEq db => Nullability db a -> Expr a -> Aggregate (Expr a)
162sgroupByExpr :: DBEq db => Nullability db a -> Expr a -> Aggregate (Expr a)
158−sgroupByExpr _ = unsafeMakeAggregate unsafeToPrimExpr unsafeFromPrimExpr Nothing
163+sgroupByExpr _ = unsafeMakeAggregate toPrimExpr fromPrimExpr Nothing