get package:persistent

Get a record by identifier, if available.

Example usage

With schema-1 and dataset-1,
getSpj :: MonadIO m => ReaderT SqlBackend m (Maybe User)
getSpj = get spjId
mspj <- getSpj
The above query when applied on dataset-1, will get this:
+------+-----+
| name | age |
+------+-----+
| SPJ  |  40 |
+------+-----+
FIXME Add documentation to that.
Get a record by unique key, if available. Returns also the identifier.

Example usage

With schema-1 and dataset-1:
getBySpjName :: MonadIO m  => ReaderT SqlBackend m (Maybe (Entity User))
getBySpjName = getBy $ UniqueUserName "SPJ"
mSpjEnt <- getBySpjName
The above query when applied on dataset-1, will get this entity:
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | SPJ  |  40 |
+----+------+-----+
A modification of getBy, which takes the PersistEntity itself instead of a Unique record. Returns a record matching one of the unique keys. This function makes the most sense on entities with a single Unique constructor.

Example usage

With schema-1 and dataset-1, getBySpjValue :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User)) getBySpjValue = getByValue $ User SPJ 999
mSpjEnt <- getBySpjValue
The above query when applied on dataset-1, will get this record:
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | SPJ  |  40 |
+----+------+-----+
Like get, but returns the complete Entity.

Example usage

With schema-1 and dataset-1,
getSpjEntity :: MonadIO m => ReaderT SqlBackend m (Maybe (Entity User))
getSpjEntity = getEntity spjId
mSpjEnt <- getSpjEntity
The above query when applied on dataset-1, will get this entity:
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | SPJ  |  40 |
+----+------+-----+
Same as get, but for a non-null (not Maybe) foreign key. Unsafe unless your database is enforcing that the foreign key is valid.

Example usage

With schema-1 and dataset-1,
getJustSpj :: MonadIO m => ReaderT SqlBackend m User
getJustSpj = getJust spjId
spj <- getJust spjId
The above query when applied on dataset-1, will get this record:
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | SPJ  |  40 |
+----+------+-----+
getJustUnknown :: MonadIO m => ReaderT SqlBackend m User
getJustUnknown = getJust unknownId
mrx <- getJustUnknown This just throws an error.
Same as getJust, but returns an Entity instead of just the record.

Example usage

With schema-1 and dataset-1,
getJustEntitySpj :: MonadIO m => ReaderT SqlBackend m (Entity User)
getJustEntitySpj = getJustEntity spjId
spjEnt <- getJustEntitySpj
The above query when applied on dataset-1, will get this entity:
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | SPJ  |  40 |
+----+------+-----+
Get many records by their respective identifiers, if available.

Example usage

With schema-1 and dataset-1:
getUsers :: MonadIO m => ReaderT SqlBackend m (Map (Key User) User)
getUsers = getMany allkeys
musers <- getUsers
The above query when applied on dataset-1, will get these records:
+----+-------+-----+
| id | name  | age |
+----+-------+-----+
|  1 | SPJ   |  40 |
+----+-------+-----+
|  2 | Simon |  41 |
+----+-------+-----+
Retrieve a record from the database using the given unique keys. It will attempt to find a matching record for each Unique in the list, and returns the first one that has a match. Returns Nothing if you provide an empty list ('[]') or if no value matches in the database.
Return the database name for the given entity.
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.
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.
Retrieve the Haskell name of the given entity.
Gets the Source of the definition of the entity. Note that as of this writing the span covers the entire file or quasiquote where the item is defined due to parsing limitations. This may be changed in a future release to be more accurate.
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.
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.
Retrieve the default name of the id column.
Retrieve the severity of the error generated when the parser encounters a quoted entity field attribute or quoted directive argument. If it is Nothing, quoted arguments are permitted in both entity field definitions and directives.
Retrieve whether or not the PersistSettings will generate code with strict fields.