@@ -5,7 +5,7 @@
55{-# language ViewPatterns #-}
66
77module Rel8.Type.Array
8− ( array, wrap
8+ ( array, encodeArrayElement
99 , listTypeInformation
1010 , nonEmptyTypeInformation
1111 )
@@ -31,7 +31,7 @@ array :: Foldable f
3131 => TypeInformation a -> f Opaleye.PrimExpr -> Opaleye.PrimExpr
3232array info =
3333 Opaleye.CastExpr (arrayType info <> "[]") .
34− Opaleye.ArrayExpr . map (wrap info) . toList
34+ Opaleye.ArrayExpr . map (encodeArrayElement info) . toList
3535{-# INLINABLE array #-}
3636
3737
@@ -42,11 +42,17 @@ listTypeInformation :: ()
4242listTypeInformation nullity info@TypeInformation {encode, decode} =
4343 TypeInformation
4444 { decode = case nullity of
45− Null -> Hasql.listArray (Hasql.nullable (unwrap info decode))
46− NotNull -> Hasql.listArray (Hasql.nonNullable (unwrap info decode))
45+ Null ->
46+ Hasql.listArray (decodeArrayElement info (Hasql.nullable decode))
47+ NotNull ->
48+ Hasql.listArray (decodeArrayElement info (Hasql.nonNullable decode))
4749 , encode = case nullity of
48− Null -> Opaleye.ArrayExpr . fmap (wrap info . maybe null encode)
49− NotNull -> Opaleye.ArrayExpr . fmap (wrap info . encode)
50+ Null ->
51+ Opaleye.ArrayExpr .
52+ fmap (encodeArrayElement info . maybe null encode)
53+ NotNull ->
54+ Opaleye.ArrayExpr .
55+ fmap (encodeArrayElement info . encode)
5056 , typeName = arrayType info <> "[]"
5157 }
5258 where
@@ -76,13 +82,13 @@ arrayType info
7682 | otherwise = typeName info
7783
7884
79−wrap :: TypeInformation a -> Opaleye.PrimExpr -> Opaleye.PrimExpr
80−wrap info
81− | isArray info = Opaleye.UnExpr (Opaleye.UnOpOther "ROW")
85+decodeArrayElement :: TypeInformation a -> Hasql.NullableOrNot Hasql.Value x -> Hasql.NullableOrNot Hasql.Value x
86+decodeArrayElement info
87+ | isArray info = Hasql.nonNullable . Hasql.composite . Hasql.field
8288 | otherwise = id
8389
8490
85−unwrap :: TypeInformation a -> Hasql.Value x -> Hasql.Value x
86−unwrap info
87− | isArray info = Hasql.composite . Hasql.field . Hasql.nonNullable
91+encodeArrayElement :: TypeInformation a -> Opaleye.PrimExpr -> Opaleye.PrimExpr
92+encodeArrayElement info
93+ | isArray info = Opaleye.UnExpr (Opaleye.UnOpOther "ROW")
8894 | otherwise = id