Safe Haskell | None |
---|---|
Language | Haskell2010 |
We use IO in the representation of Transaction, but we don't want to allow arbitrary IO, only SQL queries. So keep it private.
The SQL class refers to Transaction, and the Transaction instance refers to the class, so it all needs to be here.
Synopsis
- class Monad m => SQL (m :: * -> *) where
- query :: (ToSql p, FromSql r) => (Query, p) -> m (Vector r)
- query_ :: ToSql p => (Query, p) -> m ()
- runTransaction :: Transaction a -> m a
- newtype Transaction a = Transaction (ExceptT QueryError (ReaderT Connection IO) a)
- runTransactionIO :: Transaction a -> Connection -> IO (Either QueryError a)
Documentation
class Monad m => SQL (m :: * -> *) where Source #
An Effect class for running SQL queries. You can think of this as a context
specifying a particular Postgres connection (or connection pool). A minimal instance
defines runTransaction
. A typical instance will use runTransactionIO
or functions
in Query
and log & rethrow errors.
query :: (ToSql p, FromSql r) => (Query, p) -> m (Vector r) Source #
Run a parameterized query that returns data. The tuple argument is typically provided by
the sql
Quasiquoter.
query_ :: ToSql p => (Query, p) -> m () Source #
Run a parameterized query that does not return data.
runTransaction :: Transaction a -> m a Source #
Run multiple queries in a transaction.
Instances
SQL Transaction Source # | The same |
Defined in Preql.Effect.Internal query :: (ToSql p, FromSql r) => (Query, p) -> Transaction (Vector r) Source # query_ :: ToSql p => (Query, p) -> Transaction () Source # runTransaction :: Transaction a -> Transaction a Source # | |
(MonadTrans t, Monad (t m), SQL m) => SQL (t m) Source # | Lift through any monad transformer without a more specific instance. |
SQL (ReaderT Connection IO) Source # | Most larger applications will define an instance; this one is suitable to test out the library. |
Defined in Preql.Effect.Internal query :: (ToSql p, FromSql r) => (Query, p) -> ReaderT Connection IO (Vector r) Source # query_ :: ToSql p => (Query, p) -> ReaderT Connection IO () Source # runTransaction :: Transaction a -> ReaderT Connection IO a Source # |
Transactions
newtype Transaction a Source #
A Transaction can only contain SQL queries (and pure functions).
Instances
runTransactionIO :: Transaction a -> Connection -> IO (Either QueryError a) Source #
Run the provided Transaction
. If it fails with a QueryError
, roll back.