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

Database.Persist.EntityDef

Description

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

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.

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

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.

Since: 2.13.0.0

isEntitySum :: EntityDef -> Bool Source #

Since: 2.13.0.0

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.

Setters

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

Set an entityId to be the given FieldDef.

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

Constructors

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.

Since: 2.13.0.0

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.

Since: 2.13.0.0