persistent- Type-safe, multi-backend data serialization.
Safe HaskellNone



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.



The EntityDef type

data EntityDef Source #

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.



getEntityHaskellName :: EntityDef -> EntityNameHS Source #

Retrieve the Haskell name of the given entity.


getEntityDBName :: EntityDef -> EntityNameDB Source #

Return the database name for the given entity.


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.


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.


getEntityUniques :: EntityDef -> [UniqueDef] Source #

Retrieve the list of UniqueDef from an EntityDef. This currently does not include a Primary key, if one is defined. A future version of persistent will include a Primary key among the Unique constructors for the Entity.


isEntitySum :: EntityDef -> Bool Source #


entitiesPrimary :: EntityDef -> NonEmpty FieldDef Source #

Return the [FieldDef] for the entity keys.

keyAndEntityFields :: EntityDef -> NonEmpty FieldDef Source #

Returns a NonEmpty list of FieldDef that correspond with the key columns for an EntityDef.


setEntityId :: FieldDef -> EntityDef -> EntityDef Source #

Set an entityId to be the given FieldDef.


overEntityFields :: ([FieldDef] -> [FieldDef]) -> EntityDef -> EntityDef Source #

Perform a mapping function over all of the entity fields, as determined by getEntityFieldsDatabase.


Related Types

data EntityIdDef Source #

The definition for the entity's primary key ID.



EntityIdField !FieldDef

The entity has a single key column, and it is a surrogate key - that is, you can't go from rec -> Key rec.


EntityIdNaturalKey !CompositeDef

The entity has a natural key. This means you can write rec -> Key rec because all the key fields are present on the datatype.

A natural key can have one or more columns.