on master help sign in
Always use `ROW(NULL)` and not `NULL`
3017f59Shane O'Brien
src/Rel8/Expr/Aggregate.hs+3−3
@@ -40,7 +40,7 @@ import Rel8.Expr.Null ( null )
40import Rel8.Expr.Serialize ( litExpr )
40import Rel8.Expr.Serialize ( litExpr )
41import Rel8.Schema.Null ( Sql, Unnullify )
41import Rel8.Schema.Null ( Sql, Unnullify )
42import Rel8.Type ( DBType, typeInformation )
42import Rel8.Type ( DBType, typeInformation )
43−import Rel8.Type.Array ( wrap )
43+import Rel8.Type.Array ( encodeArrayElement )
44import Rel8.Type.Eq ( DBEq )
44import Rel8.Type.Eq ( DBEq )
45import Rel8.Type.Information ( TypeInformation )
45import Rel8.Type.Information ( TypeInformation )
46import Rel8.Type.Num ( DBNum )
46import Rel8.Type.Num ( DBNum )
@@ -189,7 +189,7 @@ slistAggExpr info = unsafeMakeAggregate to fromPrimExpr $ Just
189 , distinction = Opaleye.AggrAll
189 , distinction = Opaleye.AggrAll
190 }
190 }
191 where
191 where
192− to = wrap info . toPrimExpr
192+ to = encodeArrayElement info . toPrimExpr
193
193
194
194
195snonEmptyAggExpr :: ()
195snonEmptyAggExpr :: ()
@@ -201,4 +201,4 @@ snonEmptyAggExpr info = unsafeMakeAggregate to fromPrimExpr $ Just
201 , distinction = Opaleye.AggrAll
201 , distinction = Opaleye.AggrAll
202 }
202 }
203 where
203 where
204− to = wrap info . toPrimExpr
204+ to = encodeArrayElement info . toPrimExpr
src/Rel8/Type/Array.hs+18−12
@@ -5,7 +5,7 @@
5{-# language ViewPatterns #-}
5{-# language ViewPatterns #-}
6
6
7module Rel8.Type.Array
7module Rel8.Type.Array
8− ( array, wrap
8+ ( array, encodeArrayElement
9 , listTypeInformation
9 , listTypeInformation
10 , nonEmptyTypeInformation
10 , nonEmptyTypeInformation
11 )
11 )
@@ -31,7 +31,7 @@ array :: Foldable f
31 => TypeInformation a -> f Opaleye.PrimExpr -> Opaleye.PrimExpr
31 => TypeInformation a -> f Opaleye.PrimExpr -> Opaleye.PrimExpr
32array info =
32array info =
33 Opaleye.CastExpr (arrayType info <> "[]") .
33 Opaleye.CastExpr (arrayType info <> "[]") .
34− Opaleye.ArrayExpr . map (wrap info) . toList
34+ Opaleye.ArrayExpr . map (encodeArrayElement info) . toList
35{-# INLINABLE array #-}
35{-# INLINABLE array #-}
36
36
37
37
@@ -42,11 +42,17 @@ listTypeInformation :: ()
42listTypeInformation nullity info@TypeInformation {encode, decode} =
42listTypeInformation nullity info@TypeInformation {encode, decode} =
43 TypeInformation
43 TypeInformation
44 { decode = case nullity of
44 { decode = case nullity of
45+ Null ->
45− Null -> Hasql.listArray (Hasql.nullable (unwrap info decode))
46+ Hasql.listArray (decodeArrayElement info (Hasql.nullable decode))
47+ NotNull ->
46− NotNull -> Hasql.listArray (Hasql.nonNullable (unwrap info decode))
48+ Hasql.listArray (decodeArrayElement info (Hasql.nonNullable decode))
47 , encode = case nullity of
49 , encode = case nullity of
50+ Null ->
51+ Opaleye.ArrayExpr .
48− Null -> Opaleye.ArrayExpr . fmap (wrap info . maybe null encode)
52+ fmap (encodeArrayElement info . maybe null encode)
53+ NotNull ->
49− NotNull -> Opaleye.ArrayExpr . fmap (wrap info . encode)
54+ Opaleye.ArrayExpr .
55+ fmap (encodeArrayElement info . encode)
50 , typeName = arrayType info <> "[]"
56 , typeName = arrayType info <> "[]"
51 }
57 }
52 where
58 where
@@ -76,13 +82,13 @@ arrayType info
76 | otherwise = typeName info
82 | otherwise = typeName info
77
83
78
84
79−wrap :: TypeInformation a -> Opaleye.PrimExpr -> Opaleye.PrimExpr
85+decodeArrayElement :: TypeInformation a -> Hasql.NullableOrNot Hasql.Value x -> Hasql.NullableOrNot Hasql.Value x
80−wrap info
86+decodeArrayElement info
81− | isArray info = Opaleye.UnExpr (Opaleye.UnOpOther "ROW")
87+ | isArray info = Hasql.nonNullable . Hasql.composite . Hasql.field
82 | otherwise = id
88 | otherwise = id
83
89
84
90
85−unwrap :: TypeInformation a -> Hasql.Value x -> Hasql.Value x
91+encodeArrayElement :: TypeInformation a -> Opaleye.PrimExpr -> Opaleye.PrimExpr
86−unwrap info
92+encodeArrayElement info
87− | isArray info = Hasql.composite . Hasql.field . Hasql.nonNullable
93+ | isArray info = Opaleye.UnExpr (Opaleye.UnOpOther "ROW")
88 | otherwise = id
94 | otherwise = id