Copyright | (c) Helium Systems, Inc. |
---|---|
License | MIT |
Maintainer | patrick@helium.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
This module provdes querying with and executing SQL statements that replace
the ones found in Database.PostgreSQL.Simple
.
Please note that the parameter order is reversed when compared to the functions provided by postgresql-simple. This is a conscious choice made so as to ease use of a SQL quasiquoter.
- data PGTransactionT m a
- type PGTransaction = PGTransactionT IO
- runPGTransactionT :: MonadBaseControl IO m => PGTransactionT m a -> Connection -> m a
- runPGTransactionT' :: MonadBaseControl IO m => IsolationLevel -> PGTransactionT m a -> Connection -> m a
- runPGTransactionIO :: MonadIO m => PGTransaction a -> Connection -> m a
- query :: (ToRow input, FromRow output, MonadIO m) => input -> Query -> PGTransactionT m [output]
- query_ :: (FromRow output, MonadIO m) => Query -> PGTransactionT m [output]
- execute :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Int64
- executeOne :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Bool
- executeMany :: (ToRow input, MonadIO m) => [input] -> Query -> PGTransactionT m Int64
- returning :: (ToRow input, FromRow output, MonadIO m) => [input] -> Query -> PGTransactionT m [output]
- queryHead :: (ToRow input, FromRow output, MonadIO m) => input -> Query -> PGTransactionT m (Maybe output)
- queryOnly :: (ToRow input, FromField f, MonadIO m) => input -> Query -> PGTransactionT m (Maybe f)
- formatQuery :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Query
Documentation
data PGTransactionT m a Source
The Postgres transaction monad transformer. This is implemented as a monad transformer
so as to integrate properly with monadic logging libraries like monad-logger
or katip
.
MonadTrans PGTransactionT Source | |
Monad m => MonadReader Connection (PGTransactionT m) Source | |
Monad m => Monad (PGTransactionT m) Source | |
Functor m => Functor (PGTransactionT m) Source | |
Applicative m => Applicative (PGTransactionT m) Source | |
MonadIO m => MonadIO (PGTransactionT m) Source |
type PGTransaction = PGTransactionT IO Source
A type alias for occurrences of PGTransactionT
in the IO monad.
runPGTransactionT :: MonadBaseControl IO m => PGTransactionT m a -> Connection -> m a Source
As runPGTransactionT'
, but with the DefaultIsolationLevel
isolation level.
runPGTransactionT' :: MonadBaseControl IO m => IsolationLevel -> PGTransactionT m a -> Connection -> m a Source
Runs a transaction in the base monad m
with a provided IsolationLevel
.
An instance of MonadBaseControl is required so as to handle lifted calls to catch
correctly.
runPGTransactionIO :: MonadIO m => PGTransaction a -> Connection -> m a Source
Convenience function when there are no embedded monadic effects, only IO.
query :: (ToRow input, FromRow output, MonadIO m) => input -> Query -> PGTransactionT m [output] Source
Issue an SQL query, taking a ToRow
input and yielding FromRow
outputs.
Please note that the parameter order is different from that in the parent
postgresql-simple library; this is an intentional choice to improve the aesthetics
when using the SQL quasiquoter (making the query parameters come first means that
there is more room for the query string).
query_ :: (FromRow output, MonadIO m) => Query -> PGTransactionT m [output] Source
As query
, but for queries that take no arguments.
execute :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Int64 Source
Run a single SQL action and return success.
executeOne :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Bool Source
Run a statement and return True
if only a single record was modified.
executeMany :: (ToRow input, MonadIO m) => [input] -> Query -> PGTransactionT m Int64 Source
As executeMany
, but operating in the transaction monad.
If any one of these computations fails, the entire block will be rolled back.
returning :: (ToRow input, FromRow output, MonadIO m) => [input] -> Query -> PGTransactionT m [output] Source
Identical to returning
, save parameter order.
queryHead :: (ToRow input, FromRow output, MonadIO m) => input -> Query -> PGTransactionT m (Maybe output) Source
queryOnly :: (ToRow input, FromField f, MonadIO m) => input -> Query -> PGTransactionT m (Maybe f) Source
Lookup a single FromField value. This takes care of handling Only
for you.
formatQuery :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Query Source
As formatQuery
, save parameter order.