preql-0.2: safe PostgreSQL queries using Quasiquoters

Safe HaskellNone
LanguageHaskell2010

Preql.Effect.Internal

Contents

Description

We use IO in the representation of Transaction, but we don't want to allow arbitrary IO, only SQL queries. So keep it private.

The SQL class refers to Transaction, and the Transaction instance refers to the class, so it all needs to be here.

Synopsis

Documentation

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.

Minimal complete definition

runTransaction

Methods

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 query methods can be used within a Transaction. Nested Transactions are implemented using savepoints.

Instance details

Defined in Preql.Effect.Internal

(MonadTrans t, Monad (t m), SQL m) => SQL (t m) Source #

Lift through any monad transformer without a more specific instance.

Instance details

Defined in Preql.Effect.Internal

Methods

query :: (ToSql p, FromSql r) => (Query, p) -> t m (Vector r) Source #

query_ :: ToSql p => (Query, p) -> t m () Source #

runTransaction :: Transaction a -> t m a Source #

SQL (ReaderT Connection IO) Source #

Most larger applications will define an instance; this one is suitable to test out the library.

Instance details

Defined in Preql.Effect.Internal

Transactions

newtype Transaction a Source #

A Transaction can only contain SQL queries (and pure functions).

Instances
Monad Transaction Source # 
Instance details

Defined in Preql.Effect.Internal

Functor Transaction Source # 
Instance details

Defined in Preql.Effect.Internal

Methods

fmap :: (a -> b) -> Transaction a -> Transaction b #

(<$) :: a -> Transaction b -> Transaction a #

Applicative Transaction Source # 
Instance details

Defined in Preql.Effect.Internal

Methods

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 #

SQL Transaction Source #

The same query methods can be used within a Transaction. Nested Transactions are implemented using savepoints.

Instance details

Defined in Preql.Effect.Internal

runTransactionIO :: Transaction a -> Connection -> IO (Either QueryError a) Source #

Run the provided Transaction. If it fails with a QueryError, roll back.