preql-0.2: safe PostgreSQL queries using Quasiquoters

Safe HaskellNone
LanguageHaskell2010

Preql.Effect

Description

SQL Effect class, basically capturing some way of accessing a database.

Synopsis

Documentation

data Query Source #

The IsString instance does no validation; the limited instances discourage directly manipulating strings, with the high risk of SQL injection.

Instances
Show Query Source # 
Instance details

Defined in Preql.Wire.Internal

Methods

showsPrec :: Int -> Query -> ShowS #

show :: Query -> String #

showList :: [Query] -> ShowS #

IsString Query Source # 
Instance details

Defined in Preql.Wire.Internal

Methods

fromString :: String -> Query #

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

data 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.