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 #

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 #

A type alias for occurrences of PGTransactionT in the IO monad.

runPGTransactionT :: MonadBaseControl IO m => PGTransactionT m a -> Connection -> m a #

As runPGTransactionT', but with the DefaultIsolationLevel isolation level.

runPGTransactionT' :: MonadBaseControl IO m => IsolationLevel -> PGTransactionT m a -> Connection -> m a #

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 #

Convenience function when there are no embedded monadic effects, only IO.

query :: (ToRow input, FromRow output, MonadIO m) => input -> Query -> PGTransactionT m [output] #

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] #

As query, but for queries that take no arguments.

execute :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Int64 #

Run a single SQL action and return success.

executeOne :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Bool #

Run a statement and return True if only a single record was modified.

executeMany :: (ToRow input, MonadIO m) => [input] -> Query -> PGTransactionT m Int64 #

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] #

Identical to returning, save parameter order.

queryHead :: (ToRow input, FromRow output, MonadIO m) => input -> Query -> PGTransactionT m (Maybe output) #

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) #

Lookup a single FromField value. This takes care of handling Only for you.

formatQuery :: (ToRow input, MonadIO m) => input -> Query -> PGTransactionT m Query #

As formatQuery, save parameter order.