| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Monad.Persist
Description
This module provides an mtl-style MonadPersist typeclass for persistent,
as well as a PersistT monad transformer that implements it. If you use this
module, it is recommended that you do not import Database.Persist.Class or
Database.Persist.Sql, since this module defines its own versions of the
things defined in those modules and exports them.
Most notably, the SqlPersistT transformer defined in this module is distinct
from the SqlPersistT defined in Database.Persist.Sql.
The former is an alias for the PersistT type defined in this module, while
the latter is an alias for ReaderT over a SqlBackend.
In general, if you are using a SQL database, you should use the helper aliases
MonadSqlPersist and SqlPersistT to avoid ambiguous types and complicated
type errors.
Synopsis
- runSqlConn :: (MonadUnliftIO m, IsSqlBackend backend) => ReaderT backend m a -> backend -> m a
- runSqlPool :: (MonadUnliftIO m, IsSqlBackend backend) => ReaderT backend m a -> Pool backend -> m a
- class RawSql a
- type Sql = Text
- type CautiousMigration = [(Bool, Sql)]
- type Migration = WriterT [Text] (WriterT CautiousMigration (ReaderT SqlBackend IO)) ()
- type ConnectionPool = Pool SqlBackend
- data SqlBackend
- class (PersistStoreWrite backend, PersistEntity record, BaseBackend backend ~ PersistEntityBackend record) => DeleteCascade record backend
- class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend
- class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend
- class (PersistCore backend, PersistStoreRead backend) => PersistUniqueRead backend
- class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend
- class HasPersistBackend backend => IsPersistBackend backend
- type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend)
- class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistCore backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreRead backend
- class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistStoreRead backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreWrite backend
- data family Key record :: *
- data family Unique record :: *
- data Update record
- data SelectOpt record
- data Filter record
- data Entity record = Entity {}
- data PersistValue
- class Monad m => MonadPersist backend m | m -> backend where
- data PersistT backend m a
- runPersistT :: IsPersistBackend backend => PersistT backend m a -> backend -> m a
- type MonadSqlPersist = MonadPersist SqlBackend
- type SqlPersistT = PersistT SqlBackend
- runSqlPersistT :: MonadBaseControl IO m => SqlPersistT m a -> SqlBackend -> m a
- runSqlPoolPersistT :: MonadBaseControl IO m => SqlPersistT m a -> ConnectionPool -> m a
Documentation
runSqlConn :: (MonadUnliftIO m, IsSqlBackend backend) => ReaderT backend m a -> backend -> m a #
runSqlPool :: (MonadUnliftIO m, IsSqlBackend backend) => ReaderT backend m a -> Pool backend -> m a #
Get a connection from the pool, run the given action, and then return the connection to the pool.
Note: This function previously timed out after 2 seconds, but this behavior was buggy and caused more problems than it solved. Since version 2.1.2, it performs no timeout checks.
Class for data types that may be retrived from a rawSql
query.
Minimal complete definition
Instances
type CautiousMigration = [(Bool, Sql)] #
type Migration = WriterT [Text] (WriterT CautiousMigration (ReaderT SqlBackend IO)) () #
type ConnectionPool = Pool SqlBackend #
data SqlBackend #
Instances
| HasPersistBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal Associated Types type BaseBackend SqlBackend :: * # Methods | |
| IsPersistBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods | |
| type BaseBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal | |
| data BackendKey SqlBackend | |
Defined in Database.Persist.Sql.Orphan.PersistStore | |
class (PersistStoreWrite backend, PersistEntity record, BaseBackend backend ~ PersistEntityBackend record) => DeleteCascade record backend #
For combinations of backends and entities that support cascade-deletion. “Cascade-deletion” means that entries that depend on other entries to be deleted will be deleted as well.
Minimal complete definition
class (PersistCore backend, PersistStoreRead backend) => PersistQueryRead backend #
Backends supporting conditional read operations.
Minimal complete definition
class (PersistQueryRead backend, PersistStoreWrite backend) => PersistQueryWrite backend #
Backends supporting conditional write operations
Minimal complete definition
class (PersistCore backend, PersistStoreRead backend) => PersistUniqueRead backend #
Queries against Unique keys (other than the id Key).
Please read the general Persistent documentation to learn how to create
Unique keys.
Using this with an Entity without a Unique key leads to undefined
behavior. A few of these functions require a single Unique, so using
an Entity with multiple Uniques is also undefined. In these cases
persistent's goal is to throw an exception as soon as possible, but
persistent is still transitioning to that.
SQL backends automatically create uniqueness constraints, but for MongoDB you must manually place a unique index on a field to have a uniqueness constraint.
Minimal complete definition
class (PersistUniqueRead backend, PersistStoreWrite backend) => PersistUniqueWrite backend #
Some functions in this module (insertUnique, insertBy, and
replaceUnique) first query the unique indexes to check for
conflicts. You could instead optimistically attempt to perform the
operation (e.g. replace instead of replaceUnique). However,
- there is some fragility to trying to catch the correct exception and determing the column of failure;
- an exception will automatically abort the current SQL transaction.
Minimal complete definition
class HasPersistBackend backend => IsPersistBackend backend #
Class which witnesses that backend is essentially the same as BaseBackend backend.
That is, they're isomorphic and backend is just some wrapper over BaseBackend backend.
Minimal complete definition
Instances
| IsPersistBackend SqlBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods | |
| IsPersistBackend SqlReadBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlReadBackend -> SqlReadBackend # | |
| IsPersistBackend SqlWriteBackend | |
Defined in Database.Persist.Sql.Types.Internal Methods mkPersistBackend :: BaseBackend SqlWriteBackend -> SqlWriteBackend # | |
type PersistRecordBackend record backend = (PersistEntity record, PersistEntityBackend record ~ BaseBackend backend) #
A convenient alias for common type signatures
class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistCore backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreRead backend #
Minimal complete definition
class (Show (BackendKey backend), Read (BackendKey backend), Eq (BackendKey backend), Ord (BackendKey backend), PersistStoreRead backend, PersistField (BackendKey backend), ToJSON (BackendKey backend), FromJSON (BackendKey backend)) => PersistStoreWrite backend #
By default, a backend will automatically generate the key Instead you can specify a Primary key made up of unique values.
Instances
| (PersistEntity a, PersistEntityBackend a ~ backend, IsPersistBackend backend) => RawSql (Key a) | |
Defined in Database.Persist.Sql.Class Methods rawSqlCols :: (DBName -> Text) -> Key a -> (Int, [Text]) # rawSqlColCountReason :: Key a -> String # rawSqlProcessRow :: [PersistValue] -> Either Text (Key a) # | |
Filters which are available for select, updateWhere and
deleteWhere. Each filter constructor specifies the field being
filtered on, the type of comparison applied (equals, not equals, etc)
and the argument for the comparison.
Persistent users use combinators to create these.
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
data PersistValue #
A raw value which can be stored in any backend and can be marshalled to
and from a PersistField.
Instances
MonadPersist
class Monad m => MonadPersist backend m | m -> backend where Source #
This typeclass is a simple enumeration of the functions available from
Database.Persist.Class, simply parameterized over the monad (rather than
requiring ReaderT over MonadIO). This makes it easier to use persistent
in an arbitrary monad transformer stack. Each method corresponds directly to
a function or method defined in Database.Persist.Class or
Database.Persist.Sql. See the documentation for those modules for
information about what each method does.
This typeclass is primarily implemented by the PersistT monad transformer,
which abstracts away the role of threading a database connection through your
program. If you are using a SQL database, it is recommended that you use the
SqlPersistT alias and the corresponding runSqlPersistT function in order
to avoid unnecessarily confusing type errors and to ensure all database
access is performed within a transaction.
This module provides MonadPersist instances for various commonly-used monad
transformers, but it’s possible that you may want to use a monad transformer
from a different library that does not have an appropriate instance. In this
case, MonadPersist provides default instances for all monad transformers
using the DefaultSignatures GHC extension, which allows you to write empty
instance declarations to make any MonadTrans instance an instance of
MonadPersist:
instance MonadPersist m => MonadPersist (T m)
Methods
get :: (PersistStoreRead backend, PersistRecordBackend record backend) => Key record -> m (Maybe record) Source #
insert :: (PersistStoreWrite backend, PersistRecordBackend record backend) => record -> m (Key record) Source #
insert_ :: (PersistStoreWrite backend, PersistRecordBackend record backend) => record -> m () Source #
insertMany :: (PersistStoreWrite backend, PersistRecordBackend record backend) => [record] -> m [Key record] Source #
insertMany_ :: (PersistStoreWrite backend, PersistRecordBackend record backend) => [record] -> m () Source #
insertEntityMany :: (PersistStoreWrite backend, PersistRecordBackend record backend) => [Entity record] -> m () Source #
insertKey :: (PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> record -> m () Source #
repsert :: (PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> record -> m () Source #
replace :: (PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> record -> m () Source #
delete :: (PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> m () Source #
update :: (PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> [Update record] -> m () Source #
updateGet :: (PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> [Update record] -> m record Source #
getJust :: (PersistStoreRead backend, PersistRecordBackend record backend) => Key record -> m record Source #
belongsTo :: (PersistStoreRead backend, PersistRecordBackend record1 backend, PersistRecordBackend record2 backend) => (record1 -> Maybe (Key record2)) -> record1 -> m (Maybe record2) Source #
belongsToJust :: (PersistStoreRead backend, PersistRecordBackend record1 backend, PersistRecordBackend record2 backend) => (record1 -> Key record2) -> record1 -> m record2 Source #
insertEntity :: (PersistStoreWrite backend, PersistRecordBackend record backend) => record -> m (Entity record) Source #
getBy :: (PersistUniqueRead backend, PersistRecordBackend record backend) => Unique record -> m (Maybe (Entity record)) Source #
deleteBy :: (PersistUniqueWrite backend, PersistRecordBackend record backend) => Unique record -> m () Source #
insertUnique :: (PersistUniqueWrite backend, PersistRecordBackend record backend) => record -> m (Maybe (Key record)) Source #
upsert :: (PersistUniqueWrite backend, PersistRecordBackend record backend) => record -> [Update record] -> m (Entity record) Source #
getByValue :: (PersistUniqueRead backend, PersistRecordBackend record backend) => record -> m (Maybe (Entity record)) Source #
insertBy :: (PersistUniqueWrite backend, PersistRecordBackend record backend) => record -> m (Either (Entity record) (Key record)) Source #
replaceUnique :: (PersistUniqueWrite backend, PersistRecordBackend record backend, Eq record, Eq (Unique record)) => Key record -> record -> m (Maybe (Unique record)) Source #
checkUnique :: (PersistUniqueRead backend, PersistRecordBackend record backend) => record -> m (Maybe (Unique record)) Source #
onlyUnique :: (PersistUniqueWrite backend, PersistRecordBackend record backend) => record -> m (Unique record) Source #
selectFirst :: (PersistQueryRead backend, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> m (Maybe (Entity record)) Source #
count :: (PersistQueryRead backend, PersistRecordBackend record backend) => [Filter record] -> m Int Source #
updateWhere :: (PersistQueryWrite backend, PersistRecordBackend record backend) => [Filter record] -> [Update record] -> m () Source #
deleteWhere :: (PersistQueryWrite backend, PersistRecordBackend record backend) => [Filter record] -> m () Source #
selectList :: (PersistQueryRead backend, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> m [Entity record] Source #
selectKeysList :: (PersistQueryRead backend, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> m [Key record] Source #
deleteCascade :: DeleteCascade record backend => Key record -> m () Source #
deleteCascadeWhere :: (DeleteCascade record backend, PersistQueryWrite backend) => [Filter record] -> m () Source #
parseMigration :: backend ~ SqlBackend => Migration -> m (Either [Text] CautiousMigration) Source #
parseMigration' :: backend ~ SqlBackend => Migration -> m CautiousMigration Source #
printMigration :: backend ~ SqlBackend => Migration -> m () Source #
showMigration :: backend ~ SqlBackend => Migration -> m [Text] Source #
getMigration :: backend ~ SqlBackend => Migration -> m [Sql] Source #
runMigration :: backend ~ SqlBackend => Migration -> m () Source #
runMigrationSilent :: backend ~ SqlBackend => Migration -> m [Text] Source #
runMigrationUnsafe :: backend ~ SqlBackend => Migration -> m () Source #
rawExecute :: backend ~ SqlBackend => Text -> [PersistValue] -> m () Source #
rawExecuteCount :: backend ~ SqlBackend => Text -> [PersistValue] -> m Int64 Source #
rawSql :: (backend ~ SqlBackend, RawSql a) => Text -> [PersistValue] -> m [a] Source #
transactionSave :: backend ~ SqlBackend => m () Source #
transactionUndo :: backend ~ SqlBackend => m () Source #
get :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreRead backend, PersistRecordBackend record backend) => Key record -> m (Maybe record) Source #
insert :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => record -> m (Key record) Source #
insert_ :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => record -> m () Source #
insertMany :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => [record] -> m [Key record] Source #
insertMany_ :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => [record] -> m () Source #
insertEntityMany :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => [Entity record] -> m () Source #
insertKey :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> record -> m () Source #
repsert :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> record -> m () Source #
replace :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> record -> m () Source #
delete :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> m () Source #
update :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> [Update record] -> m () Source #
updateGet :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> [Update record] -> m record Source #
getJust :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreRead backend, PersistRecordBackend record backend) => Key record -> m record Source #
belongsTo :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreRead backend, PersistRecordBackend record1 backend, PersistRecordBackend record2 backend) => (record1 -> Maybe (Key record2)) -> record1 -> m (Maybe record2) Source #
belongsToJust :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreRead backend, PersistRecordBackend record1 backend, PersistRecordBackend record2 backend) => (record1 -> Key record2) -> record1 -> m record2 Source #
insertEntity :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => record -> m (Entity record) Source #
getBy :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueRead backend, PersistRecordBackend record backend) => Unique record -> m (Maybe (Entity record)) Source #
deleteBy :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueWrite backend, PersistRecordBackend record backend) => Unique record -> m () Source #
insertUnique :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueWrite backend, PersistRecordBackend record backend) => record -> m (Maybe (Key record)) Source #
upsert :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueWrite backend, PersistRecordBackend record backend) => record -> [Update record] -> m (Entity record) Source #
getByValue :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueRead backend, PersistRecordBackend record backend) => record -> m (Maybe (Entity record)) Source #
insertBy :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueWrite backend, PersistRecordBackend record backend) => record -> m (Either (Entity record) (Key record)) Source #
replaceUnique :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueWrite backend, PersistRecordBackend record backend, Eq record, Eq (Unique record)) => Key record -> record -> m (Maybe (Unique record)) Source #
checkUnique :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueRead backend, PersistRecordBackend record backend) => record -> m (Maybe (Unique record)) Source #
onlyUnique :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueWrite backend, PersistRecordBackend record backend) => record -> m (Unique record) Source #
selectFirst :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistQueryRead backend, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> m (Maybe (Entity record)) Source #
count :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistQueryRead backend, PersistRecordBackend record backend) => [Filter record] -> m Int Source #
updateWhere :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistQueryWrite backend, PersistRecordBackend record backend) => [Filter record] -> [Update record] -> m () Source #
deleteWhere :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistQueryWrite backend, PersistRecordBackend record backend) => [Filter record] -> m () Source #
selectList :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistQueryRead backend, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> m [Entity record] Source #
selectKeysList :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistQueryRead backend, PersistRecordBackend record backend) => [Filter record] -> [SelectOpt record] -> m [Key record] Source #
deleteCascade :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, DeleteCascade record backend) => Key record -> m () Source #
deleteCascadeWhere :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, DeleteCascade record backend, PersistQueryWrite backend) => [Filter record] -> m () Source #
parseMigration :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Migration -> m (Either [Text] CautiousMigration) Source #
parseMigration' :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Migration -> m CautiousMigration Source #
printMigration :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Migration -> m () Source #
showMigration :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Migration -> m [Text] Source #
getMigration :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Migration -> m [Sql] Source #
runMigration :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Migration -> m () Source #
runMigrationSilent :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Migration -> m [Text] Source #
runMigrationUnsafe :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Migration -> m () Source #
rawExecute :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Text -> [PersistValue] -> m () Source #
rawExecuteCount :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => Text -> [PersistValue] -> m Int64 Source #
rawSql :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend, RawSql a) => Text -> [PersistValue] -> m [a] Source #
transactionSave :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => m () Source #
transactionUndo :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, backend ~ SqlBackend) => m () Source #
upsertBy :: (PersistUniqueWrite backend, PersistRecordBackend record backend) => Unique record -> record -> [Update record] -> m (Entity record) Source #
upsertBy :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistUniqueWrite backend, PersistRecordBackend record backend) => Unique record -> record -> [Update record] -> m (Entity record) Source #
getJustEntity :: (PersistStoreRead backend, PersistRecordBackend record backend) => Key record -> m (Entity record) Source #
getEntity :: (PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> m (Maybe (Entity record)) Source #
insertRecord :: (PersistStoreWrite backend, PersistRecordBackend record backend) => record -> m record Source #
getJustEntity :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreRead backend, PersistRecordBackend record backend) => Key record -> m (Entity record) Source #
getEntity :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => Key record -> m (Maybe (Entity record)) Source #
insertRecord :: (Monad (t m'), MonadPersist backend m', MonadTrans t, t m' ~ m, PersistStoreWrite backend, PersistRecordBackend record backend) => record -> m record Source #
Instances
data PersistT backend m a Source #
A concrete monad transformer that implements MonadPersist. To run it, use
runPersistT.
If you are using a SQL database, it’s highly recommended that you use the
simpler SqlPersistT alias, instead.
Instances
runPersistT :: IsPersistBackend backend => PersistT backend m a -> backend -> m a Source #
Runs a PersistT computation with an arbitrary backend.
If you are using a SQL database, it’s highly recommended that you use
runSqlPersistT, instead, which will run the computation in a transaction.
Specialized to SqlBackend
type MonadSqlPersist = MonadPersist SqlBackend Source #
A simple alias that specializes MonadPersist to SqlBackend.
type SqlPersistT = PersistT SqlBackend Source #
A simple alias that specializes PersistT to SqlBackend.
runSqlPersistT :: MonadBaseControl IO m => SqlPersistT m a -> SqlBackend -> m a Source #
Runs a SqlPersistT computation against a SQL database. Unlike
runPersistT, the computation is run inside a transaction.
runSqlPoolPersistT :: MonadBaseControl IO m => SqlPersistT m a -> ConnectionPool -> m a Source #
Runs a SqlPersistT computation against a SQL database using a pool of
connections. The computation is run inside a transaction.