Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- tx :: (Backend b, MonadBase IO m) => Mode -> (forall s. Tx b s r) -> Session b m r
- type Mode = Maybe (IsolationLevel, Bool)
- data IsolationLevel :: *
- 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.
:: 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
.
tx :: (Backend b, MonadBase IO m) => Mode -> (forall s. Tx b s r) -> Session b m r Source
Execute a transaction in a session.
Transaction Settings
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.
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 a Statement
.
E.g.:
selectFive :: 'Backend.Statement' c 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 list 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_
.
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
RowParser b () | |
Mapping b v => RowParser b (Identity v) | |
(Mapping b v1, Mapping b v2) => RowParser b (v1, v2) | |
(Mapping b v1, Mapping b v2, Mapping b v3) => RowParser b (v1, v2, v3) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4) => RowParser b (v1, v2, v3, v4) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5) => RowParser b (v1, v2, v3, v4, v5) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6) => RowParser b (v1, v2, v3, v4, v5, v6) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7) => RowParser b (v1, v2, v3, v4, v5, v6, v7) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16, Mapping b v17) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16, Mapping b v17, Mapping b v18) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16, Mapping b v17, Mapping b v18, Mapping b v19) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16, Mapping b v17, Mapping b v18, Mapping b v19, Mapping b v20) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16, Mapping b v17, Mapping b v18, Mapping b v19, Mapping b v20, Mapping b v21) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16, Mapping b v17, Mapping b v18, Mapping b v19, Mapping b v20, Mapping b v21, Mapping b v22) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16, Mapping b v17, Mapping b v18, Mapping b v19, Mapping b v20, Mapping b v21, Mapping b v22, Mapping b v23) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) | |
(Mapping b v1, Mapping b v2, Mapping b v3, Mapping b v4, Mapping b v5, Mapping b v6, Mapping b v7, Mapping b v8, Mapping b v9, Mapping b v10, Mapping b v11, Mapping b v12, Mapping b v13, Mapping b v14, Mapping b v15, Mapping b v16, Mapping b v17, Mapping b v18, Mapping b v19, Mapping b v20, Mapping b v21, Mapping b v22, Mapping b v23, Mapping b v24) => RowParser b (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) |
Error
The only exception type that this API can raise.
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. |