| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasql.Session
Synopsis
- data Session a
- pipeline :: Pipeline result -> Session result
- script :: Text -> Session ()
- statement :: params -> Statement params result -> Session result
- onLibpqConnection :: (Connection -> IO (Either SessionError a, Connection)) -> Session a
Documentation
A sequence of operations to be executed in the context of a single database connection with exclusive access to it.
Construct sessions using helpers in this module such as
statement, pipeline and script, or use onLibpqConnection for a low-level
escape hatch.
To actually execute a Session use use, which manages
concurrent access to the shared connection state and returns either a
SessionError or the result:
result <- Hasql.Connection.use connection mySession
Note: while most session errors are returned as values, user code executed inside a session may still throw exceptions; in that case the driver will reset the connection to a clean state.
Instances
| MonadIO Session Source # | |
Defined in Hasql.Engine.Contexts.Session | |
| Applicative Session Source # | |
| Functor Session Source # | |
| Monad Session Source # | |
| MonadError SessionError Session Source # | |
Defined in Hasql.Engine.Contexts.Session Methods throwError :: SessionError -> Session a # catchError :: Session a -> (SessionError -> Session a) -> Session a # | |
script :: Text -> Session () Source #
Possibly a multi-statement query, which however cannot be parameterized or prepared, nor can any results of it be collected.
statement :: params -> Statement params result -> Session result Source #
Execute a statement by providing parameters to it.
onLibpqConnection :: (Connection -> IO (Either SessionError a, Connection)) -> Session a Source #
Execute an operation on the raw libpq connection possibly producing an error and updating the connection. This is a low-level escape hatch for custom integrations.
You can supply a new connection in the result to replace it in the running Hasql connection. The responsibility to close the old libpq connection is on you. Otherwise, just return the same connection you've received.
Producing a Left value will cause the session to fail with the given error.
Regardless of success or failure, the connection will be replaced with the one you return.
Throwing exceptions is okay. It will lead to the connection getting reset.