{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}
module Opaleye.Column (
Column,
Nullable,
null,
isNull,
matchNullable,
fromNullable,
toNullable,
maybeToNullable,
unsafeCast,
unsafeCoerceColumn,
unsafeCompositeField,
module Opaleye.Column) where
import Opaleye.Internal.Column (Column, Nullable, unsafeCoerceColumn,
unsafeCast, unsafeCompositeField)
import qualified Opaleye.Internal.Column as C
import qualified Opaleye.Internal.HaskellDB.PrimQuery as HPQ
import qualified Opaleye.PGTypes as T
import Prelude hiding (null)
null :: Column (Nullable a)
null = C.Column (HPQ.ConstExpr HPQ.NullLit)
isNull :: Column (Nullable a) -> Column T.PGBool
isNull = C.unOp HPQ.OpIsNull
matchNullable :: Column b -> (Column a -> Column b) -> Column (Nullable a)
-> Column b
matchNullable replacement f x = C.unsafeIfThenElse (isNull x) replacement
(f (unsafeCoerceColumn x))
fromNullable :: Column a -> Column (Nullable a) -> Column a
fromNullable = flip matchNullable id
toNullable :: Column a -> Column (Nullable a)
toNullable = unsafeCoerceColumn
maybeToNullable :: Maybe (Column a) -> Column (Nullable a)
maybeToNullable = maybe null toNullable
joinNullable :: Column (Nullable (Nullable a)) -> Column (Nullable a)
joinNullable = unsafeCoerceColumn