Safe Haskell | None |
---|---|
Language | Haskell2010 |
An EntityDef
represents metadata about a type that persistent
uses to
store the type in the database, as well as generate Haskell code from it.
Since: 2.13.0.0
Synopsis
- data EntityDef
- getEntityHaskellName :: EntityDef -> EntityNameHS
- getEntityDBName :: EntityDef -> EntityNameDB
- getEntityFields :: EntityDef -> [FieldDef]
- getEntityFieldsDatabase :: EntityDef -> [FieldDef]
- getEntityForeignDefs :: EntityDef -> [ForeignDef]
- getEntityUniques :: EntityDef -> [UniqueDef]
- getEntityId :: EntityDef -> EntityIdDef
- getEntityIdField :: EntityDef -> Maybe FieldDef
- getEntityKeyFields :: EntityDef -> NonEmpty FieldDef
- getEntityComments :: EntityDef -> Maybe Text
- getEntityExtra :: EntityDef -> Map Text [[Text]]
- isEntitySum :: EntityDef -> Bool
- entityPrimary :: EntityDef -> Maybe CompositeDef
- entitiesPrimary :: EntityDef -> NonEmpty FieldDef
- keyAndEntityFields :: EntityDef -> NonEmpty FieldDef
- setEntityId :: FieldDef -> EntityDef -> EntityDef
- setEntityIdDef :: EntityIdDef -> EntityDef -> EntityDef
- setEntityDBName :: EntityNameDB -> EntityDef -> EntityDef
- overEntityFields :: ([FieldDef] -> [FieldDef]) -> EntityDef -> EntityDef
- data EntityIdDef
The EntityDef
type
An EntityDef
represents the information that persistent
knows
about an Entity. It uses this information to generate the Haskell
datatype, the SQL migrations, and other relevant conversions.
Construction
Accessors
getEntityHaskellName :: EntityDef -> EntityNameHS Source #
Retrieve the Haskell name of the given entity.
Since: 2.13.0.0
getEntityDBName :: EntityDef -> EntityNameDB Source #
Return the database name for the given entity.
Since: 2.13.0.0
getEntityFields :: EntityDef -> [FieldDef] Source #
Retrieve the list of FieldDef
that makes up the fields of the entity.
This does not return the fields for an Id
column or an implicit id
. It
will return the key columns if you used the Primary
syntax for defining the
primary key.
This does not return fields that are marked SafeToRemove
or MigrationOnly
- so it only returns fields that are represented in the Haskell type. If you
need those fields, use getEntityFieldsDatabase
.
Since: 2.13.0.0
getEntityFieldsDatabase :: EntityDef -> [FieldDef] Source #
This returns all of the FieldDef
defined for the EntityDef
, including
those fields that are marked as MigrationOnly
(and therefore only present
in the database) or SafeToRemove
(and a migration will drop the column if
it exists in the database).
For all the fields that are present on the Haskell-type, see
getEntityFields
.
Since: 2.13.0.0
getEntityForeignDefs :: EntityDef -> [ForeignDef] Source #
Since: 2.13.0.0
getEntityUniques :: EntityDef -> [UniqueDef] Source #
getEntityId :: EntityDef -> EntityIdDef Source #
Since: 2.13.0.0
isEntitySum :: EntityDef -> Bool Source #
Since: 2.13.0.0
entitiesPrimary :: EntityDef -> NonEmpty FieldDef Source #
Return the [
for the entity keys.FieldDef
]
Setters
setEntityIdDef :: EntityIdDef -> EntityDef -> EntityDef Source #
Since: 2.13.0.0
setEntityDBName :: EntityNameDB -> EntityDef -> EntityDef Source #
Since: 2.13.0.0
overEntityFields :: ([FieldDef] -> [FieldDef]) -> EntityDef -> EntityDef Source #
Perform a mapping function over all of the entity fields, as determined by
getEntityFieldsDatabase
.
Since: 2.13.0.0
Related Types
data EntityIdDef Source #
The definition for the entity's primary key ID.
Since: 2.13.0.0
EntityIdField !FieldDef | The entity has a single key column, and it is a surrogate key - that
is, you can't go from Since: 2.13.0.0 |
EntityIdNaturalKey !CompositeDef | The entity has a natural key. This means you can write A natural key can have one or more columns. Since: 2.13.0.0 |