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

Safe Haskell | None
Language | Haskell2010

Database.Persist.EntityDef.Internal

Description

The `EntityDef` type, fields, and constructor are exported from this module. Breaking changes to the `EntityDef` type are not reflected in the major version of the API. Please import from Database.Persist.EntityDef instead.

If you need this module, please file a GitHub issue why.

Since: 2.13.0.0

Synopsis

- data EntityDef = EntityDef {
  - entityHaskell :: !EntityNameHS
  - entityDB :: !EntityNameDB
  - entityId :: !EntityIdDef
  - entityAttrs :: ![Attr]
  - entityFields :: ![FieldDef]
  - entityUniques :: ![UniqueDef]
  - entityForeigns :: ![ForeignDef]
  - entityDerives :: ![Text]
  - entityExtra :: !(Map Text [ExtraLine])
  - entitySum :: !Bool
  - entityComments :: !(Maybe Text)
  - entitySpan :: !(Maybe SourceSpan)
  }
- entityPrimary :: EntityDef -> Maybe CompositeDef
- entitiesPrimary :: EntityDef -> NonEmpty FieldDef
- keyAndEntityFields :: EntityDef -> NonEmpty FieldDef
- keyAndEntityFieldsDatabase :: EntityDef -> NonEmpty FieldDef
- toEmbedEntityDef :: EntityDef -> EmbedEntityDef
- data EntityIdDef
  - = EntityIdField !FieldDef
  - | EntityIdNaturalKey !CompositeDef

# Documentation

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.

Constructors

EntityDef |

Fields

- entityHaskell :: !EntityNameHS

  The name of the entity as Haskell understands it.

- entityDB :: !EntityNameDB

  The name of the database table corresponding to the entity.

- entityId :: !EntityIdDef

  The entity's primary key or identifier.

- entityAttrs :: ![Attr]

  The `persistent` entity syntax allows you to add arbitrary `Attr`s to an entity using the `!` operator. Those attributes are stored in this list.

- entityFields :: ![FieldDef]

  The fields for this entity. Note that the ID field will not be present in this list. To get all of the fields for an entity, use `keyAndEntityFields`.

- entityUniques :: ![UniqueDef]

  The Uniqueness constraints for this entity.

- entityForeigns :: ![ForeignDef]

  The foreign key relationships that this entity has to other entities.

- entityDerives :: ![Text]

  A list of type classes that have been derived for this entity.

- entityExtra :: !(Map Text [ExtraLine])
- entitySum :: !Bool

  Whether or not this entity represents a sum type in the database.

- entityComments :: !(Maybe Text)

  Optional comments on the entity.

  Since: 2.10.0

- entitySpan :: !(Maybe SourceSpan)

  Source code span occupied by this entity. May be absent if it is not known.

  Note that until a refactor is completed, these cover the entire persistent parser input rather than the particular entity in question.

  Since: 2.15.0.0

#### Instances

Instances details

Read EntityDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EntityDef Source # readList :: ReadS [EntityDef] Source # readPrec :: ReadPrec EntityDef Source # readListPrec :: ReadPrec [EntityDef] Source #
Show EntityDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EntityDef -> ShowS Source # show :: EntityDef -> String Source # showList :: [EntityDef] -> ShowS Source #
Eq EntityDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EntityDef -> EntityDef -> Bool Source # (/=) :: EntityDef -> EntityDef -> Bool Source #
Ord EntityDef Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: EntityDef -> EntityDef -> Ordering Source #

(<) :: EntityDef -> EntityDef -> Bool Source #

(<=) :: EntityDef -> EntityDef -> Bool Source #

(>) :: EntityDef -> EntityDef -> Bool Source #

(>=) :: EntityDef -> EntityDef -> Bool Source #

max :: EntityDef -> EntityDef -> EntityDef Source #

min :: EntityDef -> EntityDef -> EntityDef Source #

Lift EntityDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EntityDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EntityDef -> Code m EntityDef Source #

entityPrimary :: EntityDef -> Maybe CompositeDef 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`.

keyAndEntityFieldsDatabase :: EntityDef -> NonEmpty FieldDef Source #

Returns a `NonEmpty` list of `FieldDef` that correspond with the key columns for an `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 fields on the Haskell type use `keyAndEntityFieldsDatabase`

Since: 2.15.1.0

toEmbedEntityDef :: EntityDef -> EmbedEntityDef Source #

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

#### Instances

Instances details

Read EntityIdDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods readsPrec :: Int -> ReadS EntityIdDef Source # readList :: ReadS [EntityIdDef] Source # readPrec :: ReadPrec EntityIdDef Source # readListPrec :: ReadPrec [EntityIdDef] Source #
Show EntityIdDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods showsPrec :: Int -> EntityIdDef -> ShowS Source # show :: EntityIdDef -> String Source # showList :: [EntityIdDef] -> ShowS Source #
Eq EntityIdDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods (==) :: EntityIdDef -> EntityIdDef -> Bool Source # (/=) :: EntityIdDef -> EntityIdDef -> Bool Source #
Ord EntityIdDef Source # |

Instance details

Defined in Database.Persist.Types.Base

Methods

compare :: EntityIdDef -> EntityIdDef -> Ordering Source #

(<) :: EntityIdDef -> EntityIdDef -> Bool Source #

(<=) :: EntityIdDef -> EntityIdDef -> Bool Source #

(>) :: EntityIdDef -> EntityIdDef -> Bool Source #

(>=) :: EntityIdDef -> EntityIdDef -> Bool Source #

max :: EntityIdDef -> EntityIdDef -> EntityIdDef Source #

min :: EntityIdDef -> EntityIdDef -> EntityIdDef Source #

Lift EntityIdDef Source # |
Instance details Defined in Database.Persist.Types.Base Methods lift :: Quote m => EntityIdDef -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => EntityIdDef -> Code m EntityIdDef Source #