| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Hasql.MonadArbiter
Description
hasql implementation helpers for MonadArbiter.
Handlers receive a Hasql.Connection.Connection for running typed hasql
queries inside the worker transaction:
import Arbiter.Hasql.MonadArbiter import Hasql.Connection qualified as Hasql instance MonadArbiter MyApp where type Handler MyApp jobs result = Hasql.Connection -> jobs -> MyApp result executeQuery = hasqlExecuteQuery executeStatement = hasqlExecuteStatement withDbTransaction = hasqlWithDbTransaction runHandlerWithConnection = hasqlRunHandlerWithConnection
Synopsis
- hasqlExecuteQuery :: (HasHasqlPool m, MonadIO m) => Text -> Params -> RowCodec a -> m [a]
- hasqlExecuteStatement :: (HasHasqlPool m, MonadIO m) => Text -> Params -> m Int64
- hasqlWithDbTransaction :: (HasHasqlPool m, MonadUnliftIO m) => m a -> m a
- hasqlRunHandlerWithConnection :: (HasHasqlPool m, MonadIO m) => (Connection -> jobs -> m result) -> jobs -> m result
- data HasqlConnectionPool = HasqlConnectionPool {
- connectionPool :: Maybe (Pool Connection)
- activeConn :: Maybe Connection
- transactionDepth :: Int
- class Monad m => HasHasqlPool (m :: Type -> Type) where
- getHasqlPool :: m HasqlConnectionPool
- localHasqlPool :: (HasqlConnectionPool -> HasqlConnectionPool) -> m a -> m a
- localHasqlConnection :: HasHasqlPool m => Connection -> m a -> m a
MonadArbiter implementation
hasqlExecuteQuery :: (HasHasqlPool m, MonadIO m) => Text -> Params -> RowCodec a -> m [a] Source #
hasqlExecuteStatement :: (HasHasqlPool m, MonadIO m) => Text -> Params -> m Int64 Source #
hasqlWithDbTransaction :: (HasHasqlPool m, MonadUnliftIO m) => m a -> m a Source #
Run a block of code within a database transaction.
Supports nested transactions via savepoints, matching arbiter-simple.
hasqlRunHandlerWithConnection :: (HasHasqlPool m, MonadIO m) => (Connection -> jobs -> m result) -> jobs -> m result Source #
Invoke a handler by passing the active hasql connection.
The handler receives a Hasql.Connection so it can run typed hasql
queries within the worker transaction.
Connection pool management
data HasqlConnectionPool Source #
Connection pool state for hasql connections.
Mirrors SimpleConnectionPool from arbiter-simple.
Constructors
| HasqlConnectionPool | |
Fields
| |
class Monad m => HasHasqlPool (m :: Type -> Type) where Source #
Typeclass for monads that carry a hasql connection pool.
Methods
getHasqlPool :: m HasqlConnectionPool Source #
localHasqlPool :: (HasqlConnectionPool -> HasqlConnectionPool) -> m a -> m a Source #
Instances
| Monad m => HasHasqlPool (HasqlDb registry m) Source # | |
Defined in Arbiter.Hasql.HasqlDb Methods getHasqlPool :: HasqlDb registry m HasqlConnectionPool Source # localHasqlPool :: (HasqlConnectionPool -> HasqlConnectionPool) -> HasqlDb registry m a -> HasqlDb registry m a Source # | |
localHasqlConnection :: HasHasqlPool m => Connection -> m a -> m a Source #
Pin a hasql connection for transactional work.
All arbiter operations within the callback will use this connection.
The caller must have already issued BEGIN on the connection.