packages feed

opaleye-0.9.0.0: src/Opaleye/Column.hs

{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}
-- | Do not use.  Will be deprecated in version 0.10.  Use
-- "Opaleye.Field" instead.
--
-- Functions for working directly with 'Column's.
--
-- Please note that numeric 'Column' types are instances of 'Num', so
-- you can use '*', '/', '+', '-' on them.

module Opaleye.Column (-- * 'Column'
                       Column,
                       -- * Working with @NULL@
                       Nullable,
                       null,
                       isNull,
                       -- * Unsafe operations
                       unsafeCast,
                       unsafeCoerceColumn,
                       unsafeCompositeField,
                       -- * Entire module
                       module Opaleye.Column)  where

import           Opaleye.Internal.Column (Column, Nullable, unsafeCoerceColumn,
                                          unsafeCast, unsafeCompositeField)
import qualified Opaleye.Field as F
import qualified Opaleye.Internal.Column as C
import qualified Opaleye.Internal.HaskellDB.PrimQuery as HPQ
import qualified Opaleye.Internal.PGTypesExternal as T
import           Prelude hiding (null)

-- | A NULL of any type
null :: Column (Nullable a)
null = F.null

-- | @TRUE@ if the value of the column is @NULL@, @FALSE@ otherwise.
isNull :: Column (Nullable a) -> Column T.PGBool
isNull = C.unOp HPQ.OpIsNull

joinNullable :: Column (Nullable (Nullable a)) -> Column (Nullable a)
joinNullable = unsafeCoerceColumn