arbiter-hasql-0.1.0.0
arbiter-hasql
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 RegistryOf MyApp = MyRegistry
  type Handler MyApp job result = Hasql.Connection -> job -> MyApp result
  getSchema                = asks appSchema
  executeQuery             = hasqlExecuteQuery
  executeStatement         = hasqlExecuteStatement
  withDbTransaction        = hasqlWithDbTransaction
  runHandlerWithConnection = hasqlRunHandlerWithConnection
  getListener              = asks appListener

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

Source #hasqlExecuteQuery :: (HasHasqlPool m, MonadIO m) => Query a -> m [a]

Run a query unprepared, decoding rows.

Source #hasqlExecuteQueryPrepared :: (HasHasqlPool m, MonadIO m) => Query a -> m [a]

hasqlExecuteQuery that prepares the statement once per connection and reuses the plan, when the pool enables prepared statements.

Source #hasqlExecuteStatement :: (HasHasqlPool m, MonadIO m) => Query a -> m Int64

Run a statement unprepared, returning rows affected.

Source #hasqlWithDbTransaction :: (HasHasqlPool m, MonadUnliftIO m) => m a -> m a

Transaction bracket. Nests via savepoints.

Source #hasqlRunHandlerWithConnection :: (HasHasqlPool m, MonadIO m) => (Connection -> job -> m result) -> job -> m result

Run a handler on the active connection. The handler can issue typed hasql queries inside the worker transaction.

Connection pool management

Source #data HasqlConnectionPool

Connection pool state for hasql connections.

Constructors

HasqlConnectionPool 

Fields

Source #class Monad m => HasHasqlPool (m :: Type -> Type) where

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

Source #localHasqlConnection :: HasHasqlPool m => Connection -> m a -> m a

Pin a hasql connection for the callback. Every arbiter operation inside it runs on that connection. The caller has already issued its BEGIN.