@@ -5,7 +5,7 @@
5{-# language ViewPatterns #-}
5{-# language ViewPatterns #-}
7module Rel8.Type.Array
7module Rel8.Type.Array
8− ( array, wrap
8+ ( array, encodeArrayElement
9 , listTypeInformation
9 , listTypeInformation
10 , nonEmptyTypeInformation
10 , nonEmptyTypeInformation
@@ -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 #-}
@@ -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 -> Hasql.listArray (Hasql.nullable (unwrap info decode))
46+ Hasql.listArray (decodeArrayElement info (Hasql.nullable decode))
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
48− Null -> Opaleye.ArrayExpr . fmap (wrap info . maybe null encode)
52+ fmap (encodeArrayElement info . maybe null encode)
49− NotNull -> Opaleye.ArrayExpr . fmap (wrap info . encode)
54+ Opaleye.ArrayExpr .
55+ fmap (encodeArrayElement info . encode)
50 , typeName = arrayType info <> "[]"
56 , typeName = arrayType info <> "[]"
@@ -76,13 +82,13 @@ arrayType info
76 | otherwise = typeName info
82 | otherwise = typeName info
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
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