{-# LANGUAGE
DataKinds
, KindSignatures
, OverloadedStrings
, RankNTypes
, TypeFamilies
, TypeOperators
#-}
module Squeal.PostgreSQL.Expression.Null
(
null_
, just_
, unsafeNotNull
, monoNotNull
, coalesce
, fromNull
, isNull
, isNotNull
, matchNull
, nullIf
, CombineNullity
, notNull
) where
import Squeal.PostgreSQL.Expression
import Squeal.PostgreSQL.Expression.Logic
import Squeal.PostgreSQL.Render
import Squeal.PostgreSQL.Type.Schema
null_ :: Expr ('Null ty)
null_ :: forall (ty :: PGType). Expr ('Null ty)
null_ = forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
ByteString -> Expression grp lat with db params from ty
UnsafeExpression ByteString
"NULL"
just_ :: 'NotNull ty --> 'Null ty
just_ :: forall (ty :: PGType). 'NotNull ty --> 'Null ty
just_ = forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
ByteString -> Expression grp lat with db params from ty
UnsafeExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall sql. RenderSQL sql => sql -> ByteString
renderSQL
{-# DEPRECATED notNull "use just_ instead" #-}
notNull :: 'NotNull ty --> 'Null ty
notNull :: forall (ty :: PGType). 'NotNull ty --> 'Null ty
notNull = forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
ByteString -> Expression grp lat with db params from ty
UnsafeExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall sql. RenderSQL sql => sql -> ByteString
renderSQL
unsafeNotNull :: 'Null ty --> 'NotNull ty
unsafeNotNull :: forall (ty :: PGType). 'Null ty --> 'NotNull ty
unsafeNotNull = forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
ByteString -> Expression grp lat with db params from ty
UnsafeExpression forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall sql. RenderSQL sql => sql -> ByteString
renderSQL
monoNotNull
:: (forall null. Expression grp lat with db params from (null ty))
-> Expression grp lat with db params from ('NotNull ty)
monoNotNull :: forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: PGType).
(forall (null :: PGType -> NullType).
Expression grp lat with db params from (null ty))
-> Expression grp lat with db params from ('NotNull ty)
monoNotNull forall (null :: PGType -> NullType).
Expression grp lat with db params from (null ty)
x = forall (null :: PGType -> NullType).
Expression grp lat with db params from (null ty)
x
coalesce :: FunctionVar ('Null ty) (null ty) (null ty)
coalesce :: forall (ty :: PGType) (null :: PGType -> NullType).
FunctionVar ('Null ty) (null ty) (null ty)
coalesce [Expression grp lat with db params from ('Null ty)]
nullxs Expression grp lat with db params from (null ty)
notNullx = forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
ByteString -> Expression grp lat with db params from ty
UnsafeExpression forall a b. (a -> b) -> a -> b
$
ByteString
"COALESCE" forall a. Semigroup a => a -> a -> a
<> ByteString -> ByteString
parenthesized ([ByteString] -> ByteString
commaSeparated
((forall sql. RenderSQL sql => sql -> ByteString
renderSQL forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Expression grp lat with db params from ('Null ty)]
nullxs) forall a. Semigroup a => a -> a -> a
<> [forall sql. RenderSQL sql => sql -> ByteString
renderSQL Expression grp lat with db params from (null ty)
notNullx]))
fromNull
:: Expression grp lat with db params from ('NotNull ty)
-> Expression grp lat with db params from ('Null ty)
-> Expression grp lat with db params from ('NotNull ty)
fromNull :: forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: PGType).
Expression grp lat with db params from ('NotNull ty)
-> Expression grp lat with db params from ('Null ty)
-> Expression grp lat with db params from ('NotNull ty)
fromNull Expression grp lat with db params from ('NotNull ty)
notNullx Expression grp lat with db params from ('Null ty)
nullx = forall (ty :: PGType) (null :: PGType -> NullType).
FunctionVar ('Null ty) (null ty) (null ty)
coalesce [Expression grp lat with db params from ('Null ty)
nullx] Expression grp lat with db params from ('NotNull ty)
notNullx
isNull :: 'Null ty --> null 'PGbool
isNull :: forall (ty :: PGType) (null :: PGType -> NullType).
'Null ty --> null 'PGbool
isNull Expression grp lat with db params from ('Null ty)
x = forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
ByteString -> Expression grp lat with db params from ty
UnsafeExpression forall a b. (a -> b) -> a -> b
$ forall sql. RenderSQL sql => sql -> ByteString
renderSQL Expression grp lat with db params from ('Null ty)
x ByteString -> ByteString -> ByteString
<+> ByteString
"IS NULL"
isNotNull :: 'Null ty --> null 'PGbool
isNotNull :: forall (ty :: PGType) (null :: PGType -> NullType).
'Null ty --> null 'PGbool
isNotNull Expression grp lat with db params from ('Null ty)
x = forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
ByteString -> Expression grp lat with db params from ty
UnsafeExpression forall a b. (a -> b) -> a -> b
$ forall sql. RenderSQL sql => sql -> ByteString
renderSQL Expression grp lat with db params from ('Null ty)
x ByteString -> ByteString -> ByteString
<+> ByteString
"IS NOT NULL"
matchNull
:: Expression grp lat with db params from (nullty)
-> ( Expression grp lat with db params from ('NotNull ty)
-> Expression grp lat with db params from (nullty) )
-> Expression grp lat with db params from ('Null ty)
-> Expression grp lat with db params from (nullty)
matchNull :: forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(nullty :: NullType) (ty :: PGType).
Expression grp lat with db params from nullty
-> (Expression grp lat with db params from ('NotNull ty)
-> Expression grp lat with db params from nullty)
-> Expression grp lat with db params from ('Null ty)
-> Expression grp lat with db params from nullty
matchNull Expression grp lat with db params from nullty
y Expression grp lat with db params from ('NotNull ty)
-> Expression grp lat with db params from nullty
f Expression grp lat with db params from ('Null ty)
x = forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
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 (forall (ty :: PGType) (null :: PGType -> NullType).
'Null ty --> null 'PGbool
isNull Expression grp lat with db params from ('Null ty)
x) Expression grp lat with db params from nullty
y
(Expression grp lat with db params from ('NotNull ty)
-> Expression grp lat with db params from nullty
f (forall (grp :: Grouping) (lat :: FromType) (with :: FromType)
(db :: SchemasType) (params :: [NullType]) (from :: FromType)
(ty :: NullType).
ByteString -> Expression grp lat with db params from ty
UnsafeExpression (forall sql. RenderSQL sql => sql -> ByteString
renderSQL Expression grp lat with db params from ('Null ty)
x)))
nullIf :: '[ 'NotNull ty, 'NotNull ty] ---> 'Null ty
nullIf :: forall (ty :: PGType). '[ 'NotNull ty, 'NotNull ty] ---> 'Null ty
nullIf = forall (xs :: [NullType]) (y :: NullType).
SListI xs =>
ByteString -> xs ---> y
unsafeFunctionN ByteString
"NULLIF"
type family CombineNullity
(lhs :: PGType -> NullType) (rhs :: PGType -> NullType) :: PGType -> NullType where
CombineNullity 'NotNull 'NotNull = 'NotNull
CombineNullity _ _ = 'Null