Monad classes for running queries with Persistent and Esqueleto.
This package introduces two classes: MonadSqlBackend for monadic contexts in which a SqlBackend is available, and MonadSqlTx for contexts in which we can execute a SQL transaction.
Additionally, this package provides variants of query-running utilities from Persistent and Esqueleto which are concretized to use SqlBackend, generalized to a MonadSqlBackend m constraint rather than "ReaderT backend", and wrapped in checkpointCallStack so that exceptions will include call stacks.
persistent-sql-lifted
This package introduces two classes:
MonadSqlBackend m, for monadic contextsmin which aSqlBackendis availableMonadSqlBackend db m, for monadic contextsmin which we can execute a SQL transaction of typedb aand get a resultm a. (The typedbshould have an instance ofMonadSqlBackend.)
Additionally, this package provides variants of query-running utilities from persistent and esqueleto which are
- Concretized to use
SqlBackend; - Generalized to a
MonadSqlBackend mconstraint rather thanReaderT backend m; - Wrapped in checkpointCallStack so that exceptions will include call stacks.
How to migrate from vanilla persistent/esqueleto:
- Instead of SqlPersistT, use a
MonadSqlBackendconstraint. - Define an instance of
MonadSqlTxfor your application Monad that specifies how your application runs database transactions, e.g. by running runSqlPool. - Instead of calling
runSqlPooldirectly from the rest of your application code, use therunSqlTxmethod from theMonadSqlTxclass.
For constructing SQL expressions, you may which to import the utilities from Database.Persist.Sql.Lifted.Expression et al rather than getting them from Esqueleto. This allows you to import the specific bits you need piecemeal and without having to hide the unlifted versions of query-running functions that this package replaces. Moreover, this package contains some additional utilities.