1{-# language FlexibleContexts #-}
2{-# language NamedFieldPuns #-}
3{-# language TypeFamilies #-}
5module Rel8.Expr.Serialize
16import qualified Hasql.Decoders as Hasql
19import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
22import {-# SOURCE #-} Rel8.Expr ( Expr( Expr ) )
23import Rel8.Expr.Opaleye ( scastExpr )
24import Rel8.Schema.Nullability
25 ( Nullability( Nullable, NonNullable )
26 , Sql, nullabilization
28import Rel8.Type ( DBType, typeInformation )
29import Rel8.Type.Information ( TypeInformation(..) )
32litExpr :: Sql DBType a => a -> Expr a
33litExpr = slitExpr nullabilization typeInformation
36slitExpr :: Nullability db a -> TypeInformation db -> a -> Expr a
37slitExpr nullable info@TypeInformation {encode} =
38 scastExpr nullable info . Expr . encoder
40 encoder = case nullable of
41 Nullable -> maybe (Opaleye.ConstExpr Opaleye.NullLit) encode
45sparseValue :: Nullability db a -> TypeInformation db -> Hasql.Row a
46sparseValue nullability TypeInformation {decode, out} = case nullability of
47 Nullable -> Hasql.column $ Hasql.nullable $ out <$> decode
48 NonNullable -> Hasql.column $ Hasql.nonNullable $ out <$> decode
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