Copyright | (c) Eitan Chatav 2019 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
logical expressions and operators
Synopsis
- type Condition grp lat with db params from = Expression grp lat with db params from ('Null 'PGbool)
- true :: Expr (null 'PGbool)
- false :: Expr (null 'PGbool)
- not_ :: null 'PGbool --> null 'PGbool
- (.&&) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool)
- (.||) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool)
- caseWhenThenElse :: [(Condition grp lat with db params from, Expression grp lat with db params from ty)] -> Expression grp lat with db params from ty -> Expression grp lat with db params from ty
- ifThenElse :: Condition grp lat with db params from -> Expression grp lat with db params from ty -> Expression grp lat with db params from ty -> Expression grp lat with db params from ty
Condition
type Condition grp lat with db params from = Expression grp lat with db params from ('Null 'PGbool) Source #
A Condition
is an Expression
, which can evaluate
to true
, false
or null_
. This is because SQL uses
a three valued logic.
Logic
(.&&) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool) infixr 3 Source #
>>>
printSQL $ true .&& false
(TRUE AND FALSE)
(.||) :: Operator (null 'PGbool) (null 'PGbool) (null 'PGbool) infixr 2 Source #
>>>
printSQL $ true .|| false
(TRUE OR FALSE)
Conditional
:: [(Condition grp lat with db params from, Expression grp lat with db params from ty)] | whens and thens |
-> Expression grp lat with db params from ty | else |
-> Expression grp lat with db params from ty |
>>>
:{
let expression :: Expression grp lat with db params from (null 'PGint2) expression = caseWhenThenElse [(true, 1), (false, 2)] 3 in printSQL expression :} CASE WHEN TRUE THEN (1 :: int2) WHEN FALSE THEN (2 :: int2) ELSE (3 :: int2) END
:: Condition grp lat with db params from | |
-> Expression grp lat with db params from ty | then |
-> Expression grp lat with db params from ty | else |
-> Expression grp lat with db params from ty |
>>>
:{
let expression :: Expression grp lat with db params from (null 'PGint2) expression = ifThenElse true 1 0 in printSQL expression :} CASE WHEN TRUE THEN (1 :: int2) ELSE (0 :: int2) END