2{-# language NamedFieldPuns #-}
3{-# language OverloadedStrings #-}
8 , nonEmptyTypeInformation
9 , fromPrimArray, toPrimArray, zipPrimArraysWith
14import Data.Foldable ( toList )
15import Data.List.NonEmpty ( NonEmpty, nonEmpty )
16import Prelude hiding ( null, repeat, zipWith )
19import qualified Hasql.Decoders as Hasql
22import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
25import Rel8.Schema.Nullability ( Nullability( Nullable, NonNullable ) )
26import Rel8.Type.Information ( TypeInformation(..), parseTypeInformation )
30 => TypeInformation a -> f Opaleye.PrimExpr -> Opaleye.PrimExpr
31array TypeInformation {typeName} =
33 Opaleye.CastExpr (typeName <> "[]") .
34 Opaleye.ArrayExpr . toList
37listTypeInformation :: ()
40 -> TypeInformation [ma]
41listTypeInformation nullability info = TypeInformation
42 { decode = row $ case nullability of
43 Nullable -> Hasql.listArray (Hasql.nullable decode)
44 NonNullable -> Hasql.listArray (Hasql.nonNullable decode)
45 , encode = case nullability of
46 Nullable -> array info . fmap (maybe null encode)
47 NonNullable -> array info . fmap encode
51 TypeInformation {encode, decode} = info
52 row = Hasql.composite . Hasql.field . Hasql.nonNullable
53 null = Opaleye.ConstExpr Opaleye.NullLit
56nonEmptyTypeInformation :: ()
59 -> TypeInformation (NonEmpty ma)
60nonEmptyTypeInformation nullability =
61 parseTypeInformation parse toList . listTypeInformation nullability
63 parse = maybe (Left message) Right . nonEmpty
64 message = "failed to decode NonEmptyList: got empty list"
67fromPrimArray :: Opaleye.PrimExpr -> Opaleye.PrimExpr
68fromPrimArray = Opaleye.UnExpr (Opaleye.UnOpOther "ROW")
71toPrimArray :: Opaleye.PrimExpr -> Opaleye.PrimExpr
72toPrimArray a = Opaleye.CompositeExpr a "f1"
75zipPrimArraysWith :: ()
76 => (Opaleye.PrimExpr -> Opaleye.PrimExpr -> Opaleye.PrimExpr)
77 -> Opaleye.PrimExpr -> Opaleye.PrimExpr -> Opaleye.PrimExpr
78zipPrimArraysWith f a b = fromPrimArray (f (toPrimArray a) (toPrimArray b))
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