Safe Haskell | None |
---|---|
Language | Haskell2010 |
SQL Effect class, basically capturing some way of accessing a database.
Synopsis
- data Query
- 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
- data Transaction a
- runTransactionIO :: Transaction a -> Connection -> IO (Either QueryError a)
Documentation
The IsString instance does no validation; the limited instances discourage directly manipulating strings, with the high risk of SQL injection.
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 # |
data 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.