Safe Haskell | None |
---|---|
Language | Haskell2010 |
Effect class, expressing that a database connection is available or can be acquired, and transactions run.
Synopsis
- class Monad m => SqlQuery (m :: * -> *) where
- class SqlQuery m => SQL (m :: * -> *) where
- runTransaction' :: IsolationLevel -> Transaction a -> m a
- withConnection :: (Connection -> m a) -> m a
- queryOn :: (ToSql p, FromSql r, KnownNat (Width r)) => Connection -> (Query (Width r), p) -> m (Vector r)
- queryOn_ :: ToSql p => Connection -> (Query 0, p) -> m ()
- runTransaction :: SQL m => Transaction a -> m a
- runTransactionIO :: IsolationLevel -> Transaction a -> Connection -> IO (Either QueryError a)
- data Transaction a
Documentation
class Monad m => SqlQuery (m :: * -> *) where Source #
SqlQuery is separate from SQL
so that nested Transaction
s are
statically prevented. query
can be used directly within any
SQL
monad (running a single-statement transaction), or within a
Transaction
.
Users should not need to define instances, as every SQL
instance
implies a SqlQuery
instance.
query :: (ToSql p, FromSql r, KnownNat (Width r)) => (Query (Width r), p) -> m (Vector r) Source #
Run a parameterized query that returns data. The tuple argument is typically provided by
one of the Quasiquoters: sql
or select
query_ :: ToSql p => (Query 0, p) -> m () Source #
Run a parameterized query that does not return data.
class SqlQuery 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 withConnection
.
Override the remaining methods to log errors before rethrowing, or not to rethrow.
runTransaction' :: IsolationLevel -> Transaction a -> m a Source #
Run multiple queries in a transaction.
default runTransaction' :: MonadIO m => IsolationLevel -> Transaction a -> m a Source #
withConnection :: (Connection -> m a) -> m a Source #
runTransaction
covers the most common patterns of
mult-statement transactions. withConnection
is useful when
you want more control, or want to override the defaults that
your instance defines. For example:
- change the number of retries
- interleave calls to other services with the Postgres transaction
- ensure a prepared statement is shared among successive transactions
queryOn :: (ToSql p, FromSql r, KnownNat (Width r)) => Connection -> (Query (Width r), p) -> m (Vector r) Source #
Run a query on the specified Connection
default queryOn :: (ToSql p, FromSql r, KnownNat (Width r), MonadIO m) => Connection -> (Query (Width r), p) -> m (Vector r) Source #
queryOn_ :: ToSql p => Connection -> (Query 0, p) -> m () Source #
Instances
runTransaction :: SQL m => Transaction a -> m a Source #
Run a Transaction with full Serializable isolation.
runTransactionIO :: IsolationLevel -> Transaction a -> Connection -> IO (Either QueryError a) Source #
Run the provided Transaction
. If it fails with a QueryError
, roll back.
data Transaction a Source #
A Transaction can only contain SQL queries (and pure functions).
Instances
Monad Transaction Source # | |
Defined in Preql.Effect.Internal (>>=) :: Transaction a -> (a -> Transaction b) -> Transaction b # (>>) :: Transaction a -> Transaction b -> Transaction b # return :: a -> Transaction a # | |
Functor Transaction Source # | |
Defined in Preql.Effect.Internal fmap :: (a -> b) -> Transaction a -> Transaction b # (<$) :: a -> Transaction b -> Transaction a # | |
Applicative Transaction Source # | |
Defined in Preql.Effect.Internal pure :: a -> Transaction a # (<*>) :: Transaction (a -> b) -> Transaction a -> Transaction b # liftA2 :: (a -> b -> c) -> Transaction a -> Transaction b -> Transaction c # (*>) :: Transaction a -> Transaction b -> Transaction b # (<*) :: Transaction a -> Transaction b -> Transaction a # | |
SqlQuery Transaction Source # | |