module Database.Persist.EntityDef
(
EntityDef
, getEntityHaskellName
, getEntityDBName
, getEntityFields
, getEntityFieldsDatabase
, getEntityForeignDefs
, getEntityUniques
, getEntityId
, getEntityIdField
, getEntityKeyFields
, getEntityComments
, getEntityExtra
, isEntitySum
, entityPrimary
, entitiesPrimary
, keyAndEntityFields
, setEntityId
, setEntityIdDef
, setEntityDBName
, overEntityFields
, EntityIdDef(..)
) where
import Data.Text (Text)
import Data.Map (Map)
import Data.List.NonEmpty (NonEmpty)
import Database.Persist.EntityDef.Internal
import Database.Persist.FieldDef
import Database.Persist.Types.Base
( UniqueDef
, ForeignDef
, entityKeyFields
)
import Database.Persist.Names
getEntityUniques
:: EntityDef
-> [UniqueDef]
getEntityUniques :: EntityDef -> [UniqueDef]
getEntityUniques = EntityDef -> [UniqueDef]
entityUniques
getEntityHaskellName
:: EntityDef
-> EntityNameHS
getEntityHaskellName :: EntityDef -> EntityNameHS
getEntityHaskellName = EntityDef -> EntityNameHS
entityHaskell
getEntityDBName
:: EntityDef
-> EntityNameDB
getEntityDBName :: EntityDef -> EntityNameDB
getEntityDBName = EntityDef -> EntityNameDB
entityDB
getEntityExtra :: EntityDef -> Map Text [[Text]]
= EntityDef -> Map Text [[Text]]
entityExtra
setEntityDBName :: EntityNameDB -> EntityDef -> EntityDef
setEntityDBName :: EntityNameDB -> EntityDef -> EntityDef
setEntityDBName EntityNameDB
db EntityDef
ed = EntityDef
ed { entityDB :: EntityNameDB
entityDB = EntityNameDB
db }
getEntityComments :: EntityDef -> Maybe Text
= EntityDef -> Maybe Text
entityComments
getEntityForeignDefs
:: EntityDef
-> [ForeignDef]
getEntityForeignDefs :: EntityDef -> [ForeignDef]
getEntityForeignDefs = EntityDef -> [ForeignDef]
entityForeigns
getEntityFields
:: EntityDef
-> [FieldDef]
getEntityFields :: EntityDef -> [FieldDef]
getEntityFields = (FieldDef -> Bool) -> [FieldDef] -> [FieldDef]
forall a. (a -> Bool) -> [a] -> [a]
filter FieldDef -> Bool
isHaskellField ([FieldDef] -> [FieldDef])
-> (EntityDef -> [FieldDef]) -> EntityDef -> [FieldDef]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EntityDef -> [FieldDef]
entityFields
getEntityFieldsDatabase
:: EntityDef
-> [FieldDef]
getEntityFieldsDatabase :: EntityDef -> [FieldDef]
getEntityFieldsDatabase = EntityDef -> [FieldDef]
entityFields
isEntitySum
:: EntityDef
-> Bool
isEntitySum :: EntityDef -> Bool
isEntitySum = EntityDef -> Bool
entitySum
getEntityId
:: EntityDef
-> EntityIdDef
getEntityId :: EntityDef -> EntityIdDef
getEntityId = EntityDef -> EntityIdDef
entityId
getEntityIdField :: EntityDef -> Maybe FieldDef
getEntityIdField :: EntityDef -> Maybe FieldDef
getEntityIdField EntityDef
ed =
case EntityDef -> EntityIdDef
getEntityId EntityDef
ed of
EntityIdField FieldDef
fd ->
FieldDef -> Maybe FieldDef
forall (f :: * -> *) a. Applicative f => a -> f a
pure FieldDef
fd
EntityIdDef
_ ->
Maybe FieldDef
forall a. Maybe a
Nothing
setEntityId
:: FieldDef
-> EntityDef
-> EntityDef
setEntityId :: FieldDef -> EntityDef -> EntityDef
setEntityId FieldDef
fd = EntityIdDef -> EntityDef -> EntityDef
setEntityIdDef (FieldDef -> EntityIdDef
EntityIdField FieldDef
fd)
setEntityIdDef
:: EntityIdDef
-> EntityDef
-> EntityDef
setEntityIdDef :: EntityIdDef -> EntityDef -> EntityDef
setEntityIdDef EntityIdDef
i EntityDef
ed = EntityDef
ed { entityId :: EntityIdDef
entityId = EntityIdDef
i }
getEntityKeyFields
:: EntityDef
-> NonEmpty FieldDef
getEntityKeyFields :: EntityDef -> NonEmpty FieldDef
getEntityKeyFields = EntityDef -> NonEmpty FieldDef
entityKeyFields
setEntityFields :: [FieldDef] -> EntityDef -> EntityDef
setEntityFields :: [FieldDef] -> EntityDef -> EntityDef
setEntityFields [FieldDef]
fd EntityDef
ed = EntityDef
ed { entityFields :: [FieldDef]
entityFields = [FieldDef]
fd }
overEntityFields
:: ([FieldDef] -> [FieldDef])
-> EntityDef
-> EntityDef
overEntityFields :: ([FieldDef] -> [FieldDef]) -> EntityDef -> EntityDef
overEntityFields [FieldDef] -> [FieldDef]
f EntityDef
ed =
[FieldDef] -> EntityDef -> EntityDef
setEntityFields ([FieldDef] -> [FieldDef]
f (EntityDef -> [FieldDef]
getEntityFieldsDatabase EntityDef
ed)) EntityDef
ed