| 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 ConnectionError Connection)
- release :: Connection -> IO ()
- use :: Connection -> Session a -> IO (Either SessionError a)
Documentation
data Connection #
A single connection to the database.
acquire :: Adapter -> Settings -> IO (Either ConnectionError 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 ConnectionError in Left.
release :: Connection -> IO () #
Release the connection.
use :: Connection -> Session a -> IO (Either SessionError 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.