Hoogle Search
Within LTS Haskell 24.66 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
getEntityIdField :: EntityDef -> Maybe FieldDefpersistent Database.Persist.EntityDef No documentation available.
setEntityId :: FieldDef -> EntityDef -> EntityDefpersistent Database.Persist.EntityDef setEntityIdDef :: EntityIdDef -> EntityDef -> EntityDefpersistent Database.Persist.EntityDef No documentation available.
-
persistent Database.Persist.EntityDef.Internal The definition for the entity's primary key ID.
EntityIdField :: FieldDef -> EntityIdDefpersistent Database.Persist.EntityDef.Internal 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 -> EntityIdDefpersistent Database.Persist.EntityDef.Internal 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.
entityId :: EntityDef -> !EntityIdDefpersistent Database.Persist.EntityDef.Internal The entity's primary key or identifier.
fieldIsImplicitIdColumn :: FieldDef -> !Boolpersistent Database.Persist.FieldDef.Internal True if the field is an implicit ID column. False otherwise.
module Database.Persist.
ImplicitIdDef This module contains types and functions for creating an ImplicitIdDef, which allows you to customize the implied ID column that persistent generates. If this module doesn't suit your needs, you may want to import Database.Persist.ImplicitIdDef.Internal instead. If you do so, please file an issue on GitHub so we can support your needs. Breaking changes to that module will *not* be accompanied with a major version bump.
-
persistent Database.Persist.ImplicitIdDef A specification for how the implied ID columns are created. By default, persistent will give each table a default column named id (customizable by PersistSettings), and the column type will be whatever you'd expect from BackendKey yourBackendType. For The SqlBackend type, this is an auto incrementing integer primary key. You might want to give a different example. A common use case in postgresql is to use the UUID type, and automatically generate them using a SQL function. Previously, you'd need to add a custom Id annotation for each model.
User Id UUID default="uuid_generate_v1mc()" name Text Dog Id UUID default="uuid_generate_v1mc()" name Text user UserId
Now, you can simply create an ImplicitIdDef that corresponds to this declaration.newtype UUID = UUID ByteString instance PersistField UUID where toPersistValue (UUID bs) = PersistLiteral_ Escaped bs fromPersistValue pv = case pv of PersistLiteral_ Escaped bs -> Right (UUID bs) _ -> Left "nope" instance PersistFieldSql UUID where sqlType _ = SqlOther UUID
With this instance at the ready, we can now create our implicit definition:uuidDef :: ImplicitIdDef uuidDef = mkImplicitIdDef @UUID "uuid_generate_v1mc()"
And we can use setImplicitIdDef to use this with the MkPersistSettings for our block.mkPersist (setImplicitIdDef uuidDef sqlSettings) [persistLowerCase| ... |]
TODO: either explain interaction with mkMigrate or fix it. see issue #1249 for more details.