persistent-2.14.6.3: Type-safe, multi-backend data serialization.

Safe Haskell | None
Language | Haskell2010

Database.Persist.EntityDef

Contents

- The `EntityDef` type
- Construction
- Accessors
- Setters
- Related Types

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

- data EntityDef
- getEntityHaskellName :: EntityDef -> EntityNameHS
- getEntityDBName :: EntityDef -> EntityNameDB
- getEntityFields :: EntityDef -> [FieldDef]
- getEntityFieldsDatabase :: EntityDef -> [FieldDef]
- getEntityForeignDefs :: EntityDef -> [ForeignDef]
- getEntityUniques :: EntityDef -> [UniqueDef]
- getEntityUniquesNoPrimaryKey :: 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
  - = EntityIdField !FieldDef
  - | EntityIdNaturalKey !CompositeDef

# The `EntityDef` type

data EntityDef #

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.

#### Instances

Instances details

Read EntityDef # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EntityDef # readList :: ReadS [EntityDef] # readPrec :: ReadPrec EntityDef # readListPrec :: ReadPrec [EntityDef] #
Show EntityDef # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EntityDef -> ShowS # show :: EntityDef -> String # showList :: [EntityDef] -> ShowS #
Eq EntityDef # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EntityDef -> EntityDef -> Bool # (/=) :: EntityDef -> EntityDef -> Bool #
Ord EntityDef # |
Instance details Defined in Database.Persist.Types.Base Methods compare :: EntityDef -> EntityDef -> Ordering # (<) :: EntityDef -> EntityDef -> Bool # (<=) :: EntityDef -> EntityDef -> Bool # (>) :: EntityDef -> EntityDef -> Bool # (>=) :: EntityDef -> EntityDef -> Bool # max :: EntityDef -> EntityDef -> EntityDef # min :: EntityDef -> EntityDef -> EntityDef #
Lift EntityDef # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EntityDef -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => EntityDef -> Code m EntityDef #

# Construction

# Accessors

getEntityHaskellName :: EntityDef -> EntityNameHS #

Retrieve the Haskell name of the given entity.

Since: 2.13.0.0

getEntityDBName :: EntityDef -> EntityNameDB #

Return the database name for the given entity.

Since: 2.13.0.0

getEntityFields :: EntityDef -> [FieldDef] #

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] #

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] #

Since: 2.13.0.0

getEntityUniques :: EntityDef -> [UniqueDef] #

Retrieve the list of `UniqueDef` from an `EntityDef`. As of version 2.14, this will also include the primary key on the entity, if one is defined. If you do not want the primary key, see `getEntityUniquesNoPrimaryKey`.

Since: 2.13.0.0

getEntityUniquesNoPrimaryKey :: EntityDef -> [UniqueDef] #

Retrieve the list of `UniqueDef` from an `EntityDef`. This 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.14.0.0

getEntityId :: EntityDef -> EntityIdDef #

Since: 2.13.0.0

getEntityIdField :: EntityDef -> Maybe FieldDef #

Since: 2.13.0.0

getEntityKeyFields :: EntityDef -> NonEmpty FieldDef #

Since: 2.13.0.0

getEntityComments :: EntityDef -> Maybe Text #

getEntityExtra :: EntityDef -> Map Text [[Text]] #

isEntitySum :: EntityDef -> Bool #

Since: 2.13.0.0

entityPrimary :: EntityDef -> Maybe CompositeDef #

entitiesPrimary :: EntityDef -> NonEmpty FieldDef #

Return the `[`FieldDef`]` for the entity keys.

keyAndEntityFields :: EntityDef -> NonEmpty FieldDef #

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

# Setters

setEntityId :: FieldDef -> EntityDef -> EntityDef #

Set an `entityId` to be the given `FieldDef`.

Since: 2.13.0.0

setEntityIdDef :: EntityIdDef -> EntityDef -> EntityDef #

Since: 2.13.0.0

setEntityDBName :: EntityNameDB -> EntityDef -> EntityDef #

Since: 2.13.0.0

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

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

Since: 2.13.0.0

# Related Types

data EntityIdDef #

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

#### Instances

Instances details

Read EntityIdDef # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EntityIdDef # readList :: ReadS [EntityIdDef] # readPrec :: ReadPrec EntityIdDef # readListPrec :: ReadPrec [EntityIdDef] #
Show EntityIdDef # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EntityIdDef -> ShowS # show :: EntityIdDef -> String # showList :: [EntityIdDef] -> ShowS #
Eq EntityIdDef # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EntityIdDef -> EntityIdDef -> Bool # (/=) :: EntityIdDef -> EntityIdDef -> Bool #
Ord EntityIdDef # |
Instance details Defined in Database.Persist.Types.Base Methods compare :: EntityIdDef -> EntityIdDef -> Ordering # (<) :: EntityIdDef -> EntityIdDef -> Bool # (<=) :: EntityIdDef -> EntityIdDef -> Bool # (>) :: EntityIdDef -> EntityIdDef -> Bool # (>=) :: EntityIdDef -> EntityIdDef -> Bool # max :: EntityIdDef -> EntityIdDef -> EntityIdDef # min :: EntityIdDef -> EntityIdDef -> EntityIdDef #
Lift EntityIdDef # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EntityIdDef -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => EntityIdDef -> Code m EntityIdDef #