2{-# language NamedFieldPuns #-}
3{-# language OverloadedStrings #-}
8 , nonEmptyTypeInformation
13import Data.Foldable ( toList )
14import Data.List.NonEmpty ( NonEmpty, nonEmpty )
15import Prelude hiding ( null, repeat, zipWith )
18import qualified Hasql.Decoders as Hasql
21import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
24import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
25import Rel8.Type.Information ( TypeInformation(..), parseTypeInformation )
29 => TypeInformation a -> f Opaleye.PrimExpr -> Opaleye.PrimExpr
30array TypeInformation {typeName} =
31 Opaleye.UnExpr (Opaleye.UnOpOther "ROW") .
32 Opaleye.CastExpr (typeName <> "[]") .
33 Opaleye.ArrayExpr . toList
36listTypeInformation :: ()
39 -> TypeInformation [ma]
40listTypeInformation nullability info = TypeInformation
41 { decode = row $ case nullability of
42 Nullable -> Hasql.listArray (Hasql.nullable decode)
43 NonNullable -> Hasql.listArray (Hasql.nonNullable decode)
44 , encode = case nullability of
45 Nullable -> array info . fmap (maybe null encode)
46 NonNullable -> array info . fmap encode
50 TypeInformation {encode, decode} = info
51 row = Hasql.composite . Hasql.field . Hasql.nonNullable
52 null = Opaleye.ConstExpr Opaleye.NullLit
55nonEmptyTypeInformation :: ()
58 -> TypeInformation (NonEmpty ma)
59nonEmptyTypeInformation nullability =
60 parseTypeInformation parse toList . listTypeInformation nullability
62 parse = maybe (Left message) Right . nonEmpty
63 message = "failed to decode NonEmptyList: got empty list"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list