postgresql-transactional-1.1.1: a transactional monad on top of postgresql-simple

Copyright(c) Helium Systems, Inc.
LicenseMIT
Maintainerpatrick@helium.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Transaction

Description

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.

Synopsis

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.

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

Run a query and return Just the first result found or Nothing.

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.