Parses a quasi-quoted syntax into a list of entity definitions.
Modulepersistent-2.14.6.3Haskell2010
Database.Persist.Quasi.Internal
This Internal module may have breaking changes that will not be reflected
in major version bumps. Please use Database.Persist.Quasi instead. If you
need something in this module, please file an issue on GitHub.
- 13 types
- 20 values
- Packagepersistent-2.14.6.3
- Exports33
- LanguageHaskell2010
- LicenceMIT
- SourceInternal.hs
Constructors
PersistSettingspsToDBName :: !Text -> TextModify the Haskell-style name into a database-style name.
psToFKName :: !EntityNameHS -> ConstraintNameHS -> TextA function for generating the constraint name, with access to the entity and constraint names. Default value:
mappendpsStrictFields :: !BoolWhether fields are by default strict. Default value:
True.psIdName :: !TextThe name of the id column. Default value:
idThe name of the id column can also be changed on a per-model basis https://github.com/yesodweb/persistent/wiki/Persistent-entity-syntax
A token used by the parser.
Constructors
Token TextToken tokis tokentokalready unquoted.DocComment TextDocCommentis a documentation comment, unmodified.
Constructors
Instances3Eq, Show, Semigroup
Eq LinesWithCommentsDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow LinesWithCommentsDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalSemigroup LinesWithCommentsDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
UnboundEntityDef
19 declarationsAn EntityDef produced by the QuasiQuoter. It contains information that
the QuasiQuoter is capable of knowing about the entities. It is inherently
unfinished, though - there are many other Unbound datatypes that also
contain partial information.
The unboundEntityDef is not complete or reliable - to know which fields are safe to use, consult the parsing code.
This type was completely internal until 2.13.0.0, when it was exposed as part of the Database.Persist.Quasi.Internal module.
TODO: refactor this so we can expose it for consumers.
Constructors
UnboundEntityDefunboundForeignDefs :: [UnboundForeignDef]A list of foreign definitions on the parsed entity.
unboundPrimarySpec :: PrimarySpecThe specification for the primary key of the unbound entity.
unboundEntityDef :: EntityDefThe incomplete and partial EntityDef that we're defining. We re-use the type here to prevent duplication, but several of the fields are unset and left to defaults.
unboundEntityFields :: [UnboundFieldDef]The list of fields for the entity. We're not capable of knowing information like "is this a reference?" or "what's the underlying type of the field?" yet, so we defer those to the Template Haskell execution.
Instances4Eq, Ord, Show, Lift
Eq UnboundEntityDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalOrd UnboundEntityDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow UnboundEntityDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalLift UnboundEntityDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
Return the EntityNameHS for an UnboundEntityDef.
Convert an EntityDef into an UnboundEntityDef. This "forgets" information about the EntityDef, but it is all kept present on the unboundEntityDef field if necessary.
Returns the [UnboundFieldDef] for an UnboundEntityDef. This returns
all fields defined on the entity.
Define an explicit foreign key reference.
User
name Text
email Text
Primary name email
Dog
ownerName Text
ownerEmail Text
Foreign User fk_dog_user ownerName ownerEmail
Constructors
UnboundForeignDefunboundForeignFields :: UnboundForeignFieldListFields in the source entity.
unboundForeignDef :: ForeignDefThe ForeignDef which needs information filled in.
This value is unreliable. See the parsing code to see what data is filled in here.
Instances4Eq, Ord, Show, Lift
Eq UnboundForeignDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalOrd UnboundForeignDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow UnboundForeignDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalLift UnboundForeignDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
A representation of a database column, with everything that can be known at parse time.
Constructors
UnboundFieldDefunboundFieldNameHS :: FieldNameHSThe Haskell name of the field. This is parsed directly from the definition, and is used to generate the Haskell record field and the
EntityFielddefinition.unboundFieldNameDB :: FieldNameDBThe database name of the field. By default, this is determined by the PersistSettings record at parse time. You can customize this with a
sql=attribute:name Text sql=foo_nameunboundFieldAttrs :: [FieldAttr]The attributes present on the field. For rules on parsing and utility, see the comments on the datatype.
unboundFieldStrict :: BoolWhether or not the field should be strict in the generated Haskell code.
unboundFieldType :: FieldTypeThe type of the field, as far as is known at parse time.
The TemplateHaskell code will reconstruct a
Typeout of this, but the names will be imported as-is.unboundFieldCascade :: FieldCascadeWe parse if there's a FieldCascade on the field. If the field is not a reference, this information is ignored.
Post user UserId OnDeleteCascadeunboundFieldGenerated :: Maybe TextContains an expression to generate the column. If this is present, then the column will not be written to the database, but generated by the expression every time.
Item subtotal Int taxRate Rational total Int generated="subtotal * tax_rate"unboundFieldComments :: Maybe TextAny comments present on the field. Documentation comments use a Haskell-like syntax, and must be present before the field in question.
Post -- | This is the blog post title. title Text -- | You can have multi-line comments. -- | But each line must have the pipe character. author UserId
Instances4Eq, Ord, Show, Lift
Eq UnboundFieldDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalOrd UnboundFieldDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow UnboundFieldDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalLift UnboundFieldDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
A definition for a composite primary key.
@since.2.13.0.0
Constructors
UnboundCompositeDefunboundCompositeCols :: NonEmpty FieldNameHSThe field names for the primary key.
unboundCompositeAttrs :: [Attr]A list of attributes defined on the primary key. This is anything that occurs after a
!character.
Instances4Eq, Ord, Show, Lift
Eq UnboundCompositeDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalOrd UnboundCompositeDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow UnboundCompositeDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalLift UnboundCompositeDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
This type represents an Id declaration in the QuasiQuoted syntax.
IdThis uses the implied settings, and is equivalent to omitting the Id
statement entirely.
Id TextThis will set the field type of the ID to be Text.
Id Text sql=foo_idThis will set the field type of the Id to be Text and the SQL DB name to be foo_id.
Id FooIdThis results in a shared primary key - the FooId refers to a Foo table.
Id FooId OnDelete CascadeYou can set a cascade behavior on an ID column.
Instances4Eq, Ord, Show, Lift
Eq UnboundIdDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalOrd UnboundIdDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow UnboundIdDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalLift UnboundIdDefDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
Forget innformation about a FieldDef so it can beused as an UnboundFieldDef.
Convert an UnboundIdDef into a FieldDef suitable for use in the EntityIdField constructor.
The specification for how an entity's primary key should be formed.
Persistent requires that every table have a primary key. By default, an
implied ID is assigned, based on the mpsImplicitIdDef field on
MkPersistSettings. Because we can't access that type at parse-time, we
defer that decision until later.
Constructors
NaturalKey UnboundCompositeDefA NaturalKey contains columns that are defined on the datatype itself. This is defined using the
Primarykeyword and given a non-empty list of columns.User name Text email Text Primary name emailA natural key may also contain only a single column. A natural key with multiple columns is called a 'composite key'.
SurrogateKey UnboundIdDefA surrogate key is not part of the domain model for a database table. You can specify a custom surro
You can specify a custom surrogate key using the
Idsyntax.User Id Text name TextNote that you must provide a
default=expression when using this in order to useinsertor related functions. TheinsertKeyfunction can be used instead, as it allows you to specify a key directly. Fixing this issue is tracked in #1247 on GitHub.DefaultKey FieldNameDBThe default key for the entity using the settings in
MkPersistSettings.This is implicit - a table without an
IdorPrimarydeclaration will have a DefaultKey.
Instances4Eq, Ord, Show, Lift
Eq PrimarySpecDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalOrd PrimarySpecDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow PrimarySpecDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalLift PrimarySpecDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
Creates a default ID field.
A list of fields present on the foreign reference.
Constructors
FieldListImpliedId (NonEmpty FieldNameHS)If no
Referenceskeyword is supplied, then it is assumed that you are referring to thePrimarykey orIdof the target entity.FieldListHasReferences (NonEmpty ForeignFieldReference)You can specify the exact columns you're referring to here, if they aren't part of a primary key. Most databases expect a unique index on the columns you refer to, but Persistent doesnt' check that.
User Id UUID default="uuid_generate_v1mc()" name Text UniqueName name Dog ownerName Text Foreign User fk_dog_user ownerName References name
Instances4Eq, Ord, Show, Lift
Eq UnboundForeignFieldListDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalOrd UnboundForeignFieldListDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow UnboundForeignFieldListDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalLift UnboundForeignFieldListDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
A pairing of the FieldNameHS for the source table to the FieldNameHS for the target table.
Constructors
ForeignFieldReferenceffrSourceField :: FieldNameHSThe column on the source table.
ffrTargetField :: FieldNameHSThe column on the target table.
Instances4Eq, Ord, Show, Lift
Eq ForeignFieldReferenceDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalOrd ForeignFieldReferenceDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalShow ForeignFieldReferenceDefined in persistent-2.14.6.3 · Database.Persist.Quasi.InternalLift ForeignFieldReferenceDefined in persistent-2.14.6.3 · Database.Persist.Quasi.Internal
Convert an EntityNameHS into FieldType that will get parsed into the ID type for the entity.
>>> mkKeyConType (EntityNameHS "Hello)
FTTypeCon Nothing HelloId
Returns True if the UnboundFieldDef does not have a MigrationOnly or
SafeToRemove flag from the QuasiQuoter.
Constructors
Instances5Eq, Ord, Read, Show, Lift
Eq FieldTypeLitDefined in persistent-2.14.6.3 · Database.Persist.Types.BaseOrd FieldTypeLitDefined in persistent-2.14.6.3 · Database.Persist.Types.BaseRead FieldTypeLitDefined in persistent-2.14.6.3 · Database.Persist.Types.BaseShow FieldTypeLitDefined in persistent-2.14.6.3 · Database.Persist.Types.BaseLift FieldTypeLitDefined in persistent-2.14.6.3 · Database.Persist.Types.Base