| 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 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
- hasqlExecuteQuery :: (HasHasqlPool m, MonadIO m) => Query a -> m [a]
- hasqlExecuteQueryPrepared :: (HasHasqlPool m, MonadIO m) => Query a -> m [a]
- hasqlExecuteStatement :: (HasHasqlPool m, MonadIO m) => Query a -> m Int64
- hasqlWithDbTransaction :: (HasHasqlPool m, MonadUnliftIO m) => m a -> m a
- hasqlRunHandlerWithConnection :: (HasHasqlPool m, MonadIO m) => (Connection -> job -> m result) -> job -> m result
- data HasqlConnectionPool = HasqlConnectionPool {}
- 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
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.
Methods
Source #getHasqlPool :: m HasqlConnectionPool
Source #localHasqlPool :: (HasqlConnectionPool -> HasqlConnectionPool) -> m a -> m a
Instances
| Monad m => HasHasqlPool (HasqlDb registry m) Source # | |
Defined in Arbiter.Hasql.HasqlDb Methods Source #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
Pin a hasql connection for the callback. Every arbiter operation inside it runs on
that connection. The caller has already issued its BEGIN.