hasql-backend-0.4.3: API for backends of "hasql"

Safe HaskellNone
LanguageHaskell2010

Hasql.Backend

Contents

Description

An open API for implementation of specific backend drivers.

Synopsis

Connection

class Cx c where Source #

Minimal complete definition

acquireCx, releaseCx

Associated Types

type CxSettings c Source #

Connection settings.

type CxError c Source #

A connection acquisition error.

Methods

acquireCx :: CxSettings c -> IO (Either (CxError c) c) Source #

releaseCx :: c -> IO () Source #

Results

data family ResultValue c Source #

A raw value returned from the database.

type ResultRow c = Vector (ResultValue c) Source #

A raw result row.

type ResultStream c = ListT IO (ResultRow c) Source #

A stream of rows of a result.

type ResultMatrix c = Vector (ResultRow c) Source #

A matrix of a result.

Statements

data Stmt c Source #

A statement template packed with its values and settings.

Constructors

Stmt 

data family StmtParam c Source #

A prepared statement parameter.

Mapping

class CxValue c v where Source #

A support by a backend of mapping a specific data type.

Minimal complete definition

encodeValue, decodeValue

Transaction

class CxTx c where Source #

A transaction execution support.

Minimal complete definition

runTx

Associated Types

type TxError c Source #

A transaction error.

Methods

runTx :: c -> TxMode -> Tx c a -> IO (Either (TxError c) (Maybe a)) Source #

Given an established connection execute a transaction, returning either an error or a maybe result, in which a Nothing indicates that the transaction should be retried.

type TxMode = Maybe (TxIsolationLevel, TxWriteMode) Source #

A mode, defining how a transaction should be executed.

  • Just (isolationLevel, write) indicates that a database transaction should be established with a specified isolation level and a write mode.
  • Nothing indicates that there should be no database transaction established on the backend and therefore it should be executed with no ACID guarantees, but also without any induced overhead.

type TxWriteMode = Maybe Bool Source #

  • Nothing indicates a "read" mode.
  • Just True indicates a "write" mode.
  • Just False indicates a "write" mode without committing. This is useful for testing, allowing you to modify your database, producing some result based on your changes, and to let Hasql roll all the changes back on the exit from the transaction.

type Tx c = FreeT (TxF c) (MaybeT (EitherT (TxError c) IO)) Source #

data TxF c x Source #

Constructors

UnitTx (Stmt c) x 
CountTx (Stmt c) (Word64 -> x) 
VectorTx (Stmt c) (Vector (ResultRow c) -> x) 
StreamTx Int (Stmt c) (ListT (Tx c) (ResultRow c) -> x) 

Instances

Functor (TxF c) Source # 

Methods

fmap :: (a -> b) -> TxF c a -> TxF c b #

(<$) :: a -> TxF c b -> TxF c a #

unitTx :: Stmt c -> Tx c () Source #

streamTx :: Int -> Stmt c -> Tx c (ListT (Tx c) (ResultRow c)) Source #