Safe Haskell | None |
---|---|
Language | Haskell2010 |
Hasql
Contents
Description
This is the API of the "hasql" library. For an introduction to the package and links to more documentation please refer to the package's index page.
- type Session b = ReaderT (Pool (Connection b))
- session :: Backend b => MonadBaseControl IO m => b -> SessionSettings -> Session b m r -> m r
- data SessionSettings
- sessionSettings :: Word32 -> NominalDiffTime -> Maybe SessionSettings
- data Tx b s r
- type Mode = Maybe (IsolationLevel, Bool)
- data IsolationLevel :: *
- tx :: Backend b => MonadBase IO m => Mode -> (forall s. Tx b s r) -> Session b m r
- q :: QuasiQuoter
- unit :: Backend b => Statement b -> Tx b s ()
- count :: Backend b => Mapping b Word64 => Statement b -> Tx b s Word64
- single :: Backend b => RowParser b r => Statement b -> Tx b s (Maybe r)
- list :: Backend b => RowParser b r => Statement b -> Tx b s [r]
- stream :: Backend b => RowParser b r => Statement b -> TxListT s (Tx b s) r
- data TxListT s m r
- class RowParser b r where
- data Error
Session
type Session b = ReaderT (Pool (Connection b)) Source
A monad transformer, which executes transactions.
session :: Backend b => MonadBaseControl IO m => b -> SessionSettings -> Session b m r -> m r Source
Given backend settings, session settings, and a session monad transformer, execute it in the inner monad.
Session Settings
data SessionSettings Source
Settings of a session.
Arguments
:: Word32 | The maximum number of connections to keep open. The smallest acceptable value is 1. Requests for connections will block if this limit is reached. |
-> NominalDiffTime | The amount of time for which an unused connection is kept open. The smallest acceptable value is 0.5 seconds. |
-> Maybe SessionSettings | Maybe session settings, if they are correct. |
A smart constructor for session settings.
Transaction
A transaction specialized for backend b
,
running on an anonymous state-thread s
and producing a result r
.
type Mode = Maybe (IsolationLevel, Bool) Source
A transaction 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 boolean, defining, whether it would perform any modification operations.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.
data IsolationLevel :: *
For reference see the Wikipedia info.
Constructors
Serializable | |
RepeatableReads | |
ReadCommitted | |
ReadUncommitted |
tx :: Backend b => MonadBase IO m => Mode -> (forall s. Tx b s r) -> Session b m r Source
Execute a transaction in a session.
Statement Quasi-Quoter
q :: QuasiQuoter Source
Produces a lambda-expression,
which takes as many parameters as there are placeholders in the quoted text
and results in an expression of type Statement
.
E.g.:
selectFive :: Statement b selectFive = [q|SELECT (? + ?)|] 2 3
Statement Execution
count :: Backend b => Mapping b Word64 => Statement b -> Tx b s Word64 Source
Execute a statement and count the amount of affected rows. Useful for resolving how many rows were updated or deleted.
single :: Backend b => RowParser b r => Statement b -> Tx b s (Maybe r) Source
Execute a statement,
which produces a single result row:
a SELECT
or an INSERT
, which produces a generated value (e.g., an auto-incremented id).
list :: Backend b => RowParser b r => Statement b -> Tx b s [r] Source
Execute a SELECT
statement,
and produce a vector of results.
stream :: Backend b => RowParser b r => Statement b -> TxListT s (Tx b s) r Source
Execute a SELECT
statement with a cursor,
and produce a results stream.
Cursor allows you to fetch virtually limitless results in a constant memory
at a cost of a small overhead.
Note that in most databases cursors require establishing a database transaction,
so a NotInTransaction
error will be raised if you run it improperly.
Results Stream
A stream of results, which fetches only those that you reach.
It's a wrapper around ListT
,
which uses the same trick as the ST
monad to associate with the
context transaction and become impossible to be used outside of it.
This lets the library ensure that it is safe to automatically
release all the resources associated with this stream.
All the functions of the "list-t" library are applicable to this type,
amongst which are head
, toList
, fold
, traverse_
.
Instances
ListTrans (TxListT s) | |
MonadTrans (TxListT s) | |
(Monad m, Functor m) => Alternative (TxListT s m) | |
Monad m => Monad (TxListT s m) | |
Functor m => Functor (TxListT s m) | |
Monad m => MonadPlus (TxListT s m) | |
(Monad m, Functor m) => Applicative (TxListT s m) | |
Monad m => ListMonad (TxListT s m) | |
Monad m => Monoid (TxListT s m r) |
Row parser
class RowParser b r where Source
Instances
RowParser b () | |
Mapping b v => RowParser b (Identity v) | |
(Mapping b _1, Mapping b _2) => RowParser b (_1, _2) | |
(Mapping b _1, Mapping b _2, Mapping b _3) => RowParser b (_1, _2, _3) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4) => RowParser b (_1, _2, _3, _4) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5) => RowParser b (_1, _2, _3, _4, _5) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6) => RowParser b (_1, _2, _3, _4, _5, _6) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7) => RowParser b (_1, _2, _3, _4, _5, _6, _7) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16, Mapping b _17) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16, Mapping b _17, Mapping b _18) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16, Mapping b _17, Mapping b _18, Mapping b _19) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16, Mapping b _17, Mapping b _18, Mapping b _19, Mapping b _20) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16, Mapping b _17, Mapping b _18, Mapping b _19, Mapping b _20, Mapping b _21) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16, Mapping b _17, Mapping b _18, Mapping b _19, Mapping b _20, Mapping b _21, Mapping b _22) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16, Mapping b _17, Mapping b _18, Mapping b _19, Mapping b _20, Mapping b _21, Mapping b _22, Mapping b _23) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23) | |
(Mapping b _1, Mapping b _2, Mapping b _3, Mapping b _4, Mapping b _5, Mapping b _6, Mapping b _7, Mapping b _8, Mapping b _9, Mapping b _10, Mapping b _11, Mapping b _12, Mapping b _13, Mapping b _14, Mapping b _15, Mapping b _16, Mapping b _17, Mapping b _18, Mapping b _19, Mapping b _20, Mapping b _21, Mapping b _22, Mapping b _23, Mapping b _24) => RowParser b (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24) |
Error
The only exception type that this API can raise.
Constructors
CantConnect Text | Cannot connect to a server. |
ConnectionLost Text | The connection got interrupted. |
ErroneousResult Text | An error returned from the database. |
UnexpectedResult Text | Unexpected result structure. Indicates usage of inappropriate statement executor. |
UnparsableTemplate Text | Incorrect statement template. |
NotInTransaction | An operation, which requires a database transaction was executed without one. |
UnparsableRow Text | Attempt to parse a row into an incompatible type. Indicates either a mismatching schema or an incorrect query. |