arbiter-hasql-0.1.0.0: Hasql backend for arbiter
Safe HaskellNone
LanguageGHC2024

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

MonadArbiter implementation

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.

Instances

Instances details
Monad m => HasHasqlPool (HasqlDb registry m) Source # 
Instance details

Defined in Arbiter.Hasql.HasqlDb

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.