module Database.Persist.FieldDef
(
FieldDef
, setFieldAttrs
, overFieldAttrs
, addFieldAttr
, isFieldNullable
, isFieldMaybe
, isFieldNotGenerated
, isHaskellField
, FieldCascade(..)
, renderFieldCascade
, renderCascadeAction
, noCascade
, CascadeAction(..)
) where
import Database.Persist.FieldDef.Internal
import Database.Persist.Types.Base
( FieldAttr(..)
, FieldType(..)
, IsNullable(..)
, fieldAttrsContainsNullable
, isHaskellField
)
setFieldAttrs :: [FieldAttr] -> FieldDef -> FieldDef
setFieldAttrs :: [FieldAttr] -> FieldDef -> FieldDef
setFieldAttrs [FieldAttr]
fas FieldDef
fd = FieldDef
fd { fieldAttrs :: [FieldAttr]
fieldAttrs = [FieldAttr]
fas }
overFieldAttrs :: ([FieldAttr] -> [FieldAttr]) -> FieldDef -> FieldDef
overFieldAttrs :: ([FieldAttr] -> [FieldAttr]) -> FieldDef -> FieldDef
overFieldAttrs [FieldAttr] -> [FieldAttr]
k FieldDef
fd = FieldDef
fd { fieldAttrs :: [FieldAttr]
fieldAttrs = [FieldAttr] -> [FieldAttr]
k (FieldDef -> [FieldAttr]
fieldAttrs FieldDef
fd) }
addFieldAttr :: FieldAttr -> FieldDef -> FieldDef
addFieldAttr :: FieldAttr -> FieldDef -> FieldDef
addFieldAttr FieldAttr
fa = ([FieldAttr] -> [FieldAttr]) -> FieldDef -> FieldDef
overFieldAttrs (FieldAttr
fa forall a. a -> [a] -> [a]
:)
isFieldNullable :: FieldDef -> IsNullable
isFieldNullable :: FieldDef -> IsNullable
isFieldNullable =
[FieldAttr] -> IsNullable
fieldAttrsContainsNullable forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldDef -> [FieldAttr]
fieldAttrs
isFieldMaybe :: FieldDef -> Bool
isFieldMaybe :: FieldDef -> Bool
isFieldMaybe FieldDef
field =
case FieldDef -> FieldType
fieldType FieldDef
field of
FTApp (FTTypeCon Maybe Text
_ Text
"Maybe") FieldType
_ ->
Bool
True
FieldType
_ ->
Bool
False