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.Null ( Unnullify, Nullity( Null, NotNull ), Sql, nullable )
25import Rel8.Type ( DBType, typeInformation )
26import Rel8.Type.Information ( TypeInformation(..) )
29-- | Produce an expression from a literal.
31-- Note that you can usually use 'Rel8.lit', but @litExpr@ can solve problems
32-- of inference in polymorphic code.
33litExpr :: Sql DBType a => a -> Expr a
34litExpr = slitExpr nullable typeInformation
37slitExpr :: Nullity a -> TypeInformation (Unnullify a) -> a -> Expr a
38slitExpr nullity info@TypeInformation {encode} =
39 scastExpr info . Expr . encoder
41 encoder = case nullity of
42 Null -> maybe (Opaleye.ConstExpr Opaleye.NullLit) encode
46sparseValue :: Nullity a -> TypeInformation (Unnullify a) -> Hasql.Row a
47sparseValue nullity TypeInformation {decode} = case nullity of
48 Null -> Hasql.column $ Hasql.nullable decode
49 NotNull -> Hasql.column $ Hasql.nonNullable 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