arbiter-hasql-0.1.0.0
arbiter-hasql
Safe HaskellNone
LanguageGHC2024

Arbiter.Hasql.MonadArbiter

Description

hasql primitives for writing a custom MonadArbiter instance.

Handlers receive a Hasql.Connection.Connection for running typed hasql queries inside the worker transaction:

import Arbiter.Core qualified as Arb
import Arbiter.Hasql qualified as ArbH
import Hasql.Connection qualified as Hasql

instance Arb.MonadArbiter MyApp where
  type RegistryOf MyApp = MyRegistry
  type Handler MyApp job result = Hasql.Connection -> job -> MyApp result
  getSchema                = asks appSchema
  executeQuery             = ArbH.hasqlExecuteQuery
  executeQueryPrepared     = ArbH.hasqlExecuteQueryPrepared True
  executeStatement         = ArbH.hasqlExecuteStatement
  withDbTransaction        = ArbH.hasqlWithDbTransaction
  runHandlerWithConnection = ArbH.hasqlRunHandlerWithConnection
  getListener              = asks appListener

The primitives also need a HasPoolState Hasql.Connection MyApp instance. See HasPoolState.

Write a handler's own signature as JobHandler MyApp MyPayload MyResult, which is Handler at that queue's job and declared result types.

Synopsis

MonadArbiter implementation

hasqlExecuteQuery :: (HasPoolState Connection m, MonadUnliftIO m) => Query a -> m [a]Source #

Run a query unprepared, decoding rows.

hasqlExecuteQueryPrepared :: (HasPoolState Connection m, MonadUnliftIO m) => Bool -> Query a -> m [a]Source #

hasqlExecuteQuery, prepared once per connection when the flag is on.

hasqlExecuteStatement :: (HasPoolState Connection m, MonadUnliftIO m) => Query a -> m Int64Source #

Run a statement unprepared, returning rows affected.

hasqlWithDbTransaction :: (HasPoolState Connection m, MonadUnliftIO m) => m a -> m aSource #

Transaction bracket. Nests via savepoints.

hasqlRunHandlerWithConnection :: (HasPoolState Connection m, MonadUnliftIO m) => (Connection -> job -> m result) -> job -> m resultSource #

Run a handler on the pinned connection, or on a borrowed pool connection when none is pinned.

Connection

hasqlWithConnection :: (HasPoolState Connection m, MonadUnliftIO m) => m a -> m aSource #

Pin one pooled connection for the action.