| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasql.Connection
Description
This module provides a low-level effectful API dealing with the connections to the database.
Synopsis
- data Connection
- acquire :: Adapter -> Settings -> IO (Either AcquireError Connection)
- release :: Connection -> IO ()
- use :: Connection -> Session a -> IO (Either UseError a)
Documentation
data Connection #
A single connection to the database.
acquire :: Adapter -> Settings -> IO (Either AcquireError Connection) #
Establish a connection according to the provided settings.
The first argument is an Adapter, which defines the backend
implementation used to talk to PostgreSQL (for example, libpq via the
pqi-ffi package, or a pure
Haskell implementation via the
pqi-native package).
This is the only place in the library where users choose the adapter.
This function:
- Opens a PostgreSQL connection using the constructed connection string.
- Validates that the connection is healthy.
- Checks the server version for compatibility.
- Initializes session-level settings (encoding and message verbosity).
On success, returns a Connection wrapped in Right.
On failure, returns a classified AcquireError in Left.
release :: Connection -> IO () #
Release the connection.
Idempotent: releasing a connection that is already gone - released
before, or finished by use - does nothing.
use :: Connection -> Session a -> IO (Either UseError a) #
Execute a sequence of operations with exclusive access to the connection.
Blocks until the connection is available when there is another session running upon the connection on a different thread.
An exception thrown out of the session - including an interruption
delivered from another thread, as timeout and
killThread do - propagates, and the connection is
finished on the way out. See the note on the exception path below for why
it is not repaired instead.