{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
module Opaleye.Field (
Field_,
Field,
FieldNullable,
Nullability(..),
C.unsafeCast,
unsafeCoerceField,
Opaleye.Field.null,
isNull,
matchNullable,
fromNullable,
toNullable,
maybeToNullable,
) where
import Prelude hiding (null)
import Opaleye.Internal.Column
(Field_(Column), FieldNullable, Field, Nullability(NonNullable, Nullable))
import qualified Opaleye.Internal.Column as C
import qualified Opaleye.Internal.PGTypesExternal as T
import qualified Opaleye.Internal.HaskellDB.PrimQuery as HPQ
null :: FieldNullable a
null :: forall a. FieldNullable a
null = forall (n :: Nullability) sqlType. PrimExpr -> Field_ n sqlType
Column (Literal -> PrimExpr
HPQ.ConstExpr Literal
HPQ.NullLit)
isNull :: FieldNullable a -> Field T.PGBool
isNull :: forall a. FieldNullable a -> Field PGBool
isNull = forall (n :: Nullability) a (n' :: Nullability) b.
UnOp -> Field_ n a -> Field_ n' b
C.unOp UnOp
HPQ.OpIsNull
matchNullable :: Field b
-> (Field a -> Field b)
-> FieldNullable a
-> Field b
matchNullable :: forall b a.
Field b -> (Field a -> Field b) -> FieldNullable a -> Field b
matchNullable Field b
replacement Field a -> Field b
f FieldNullable a
x = forall (n' :: Nullability) pgBool (n :: Nullability) a.
Field_ n' pgBool -> Field_ n a -> Field_ n a -> Field_ n a
C.unsafeIfThenElse (forall a. FieldNullable a -> Field PGBool
isNull FieldNullable a
x) Field b
replacement
(Field a -> Field b
f (forall (n :: Nullability) a (n' :: Nullability) b.
Field_ n a -> Field_ n' b
unsafeCoerceField FieldNullable a
x))
fromNullable :: Field a
-> FieldNullable a
-> Field a
fromNullable :: forall a. Field a -> FieldNullable a -> Field a
fromNullable = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall b a.
Field b -> (Field a -> Field b) -> FieldNullable a -> Field b
matchNullable forall a. a -> a
id
toNullable :: Field a -> FieldNullable a
toNullable :: forall a. Field a -> FieldNullable a
toNullable = forall (n :: Nullability) a (n' :: Nullability) b.
Field_ n a -> Field_ n' b
C.unsafeCoerceColumn
maybeToNullable :: Maybe (Field a)
-> FieldNullable a
maybeToNullable :: forall a. Maybe (Field a) -> FieldNullable a
maybeToNullable = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. FieldNullable a
null forall a. Field a -> FieldNullable a
toNullable
unsafeCoerceField :: Field_ n a -> Field_ n' b
unsafeCoerceField :: forall (n :: Nullability) a (n' :: Nullability) b.
Field_ n a -> Field_ n' b
unsafeCoerceField = forall (n :: Nullability) a (n' :: Nullability) b.
Field_ n a -> Field_ n' b
C.unsafeCoerceColumn