Safe Haskell | None |
---|---|
Language | Haskell2010 |
Prolude.Persist
Synopsis
- data Entity record = Entity {}
- keyToOid :: ToBackendKey MongoContext record => Key record -> ObjectId
- oidToKey :: ToBackendKey MongoContext record => ObjectId -> Key record
Documentation
Datatype that represents an entity, with both its Key
and
its Haskell record representation.
When using a SQL-based backend (such as SQLite or
PostgreSQL), an Entity
may take any number of columns
depending on how many fields it has. In order to reconstruct
your entity on the Haskell side, persistent
needs all of
your entity columns and in the right order. Note that you
don't need to worry about this when using persistent
's API
since everything is handled correctly behind the scenes.
However, if you want to issue a raw SQL command that returns
an Entity
, then you have to be careful with the column
order. While you could use SELECT Entity.* WHERE ...
and
that would work most of the time, there are times when the
order of the columns on your database is different from the
order that persistent
expects (for example, if you add a new
field in the middle of you entity definition and then use the
migration code -- persistent
will expect the column to be in
the middle, but your DBMS will put it as the last column).
So, instead of using a query like the one above, you may use
rawSql
(from the
Database.Persist.GenericSql module) with its /entity
selection placeholder/ (a double question mark ??
). Using
rawSql
the query above must be written as SELECT ?? WHERE
..
. Then rawSql
will replace ??
with the list of all
columns that we need from your entity in the right order. If
your query returns two entities (i.e. (Entity backend a,
Entity backend b)
), then you must you use SELECT ??, ??
WHERE ...
, and so on.
Instances
(Eq (Key record), Eq record) => Eq (Entity record) | |
(Ord (Key record), Ord record) => Ord (Entity record) | |
Defined in Database.Persist.Class.PersistEntity Methods compare :: Entity record -> Entity record -> Ordering # (<) :: Entity record -> Entity record -> Bool # (<=) :: Entity record -> Entity record -> Bool # (>) :: Entity record -> Entity record -> Bool # (>=) :: Entity record -> Entity record -> Bool # | |
(Read (Key record), Read record) => Read (Entity record) | |
(Show (Key record), Show record) => Show (Entity record) | |
(Generic (Key record), Generic record) => Generic (Entity record) | |
(PersistEntity record, PersistField record, PersistField (Key record)) => PersistField (Entity record) | |
Defined in Database.Persist.Class.PersistEntity Methods toPersistValue :: Entity record -> PersistValue # fromPersistValue :: PersistValue -> Either Text (Entity record) # | |
type Rep (Entity record) | |
Defined in Database.Persist.Class.PersistEntity type Rep (Entity record) = D1 ('MetaData "Entity" "Database.Persist.Class.PersistEntity" "persistent-2.11.0.2-IWMGXmX4o5r2Bf5DB8BjlF" 'False) (C1 ('MetaCons "Entity" 'PrefixI 'True) (S1 ('MetaSel ('Just "entityKey") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Key record)) :*: S1 ('MetaSel ('Just "entityVal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 record))) |
keyToOid :: ToBackendKey MongoContext record => Key record -> ObjectId #
oidToKey :: ToBackendKey MongoContext record => ObjectId -> Key record #