arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.MonadArbiter

Description

The database primitives every backend implements.

Synopsis

Documentation

Source #class MonadUnliftIO m => MonadArbiter (m :: Type -> Type) where

Database abstraction for job queue operations. Each backend (postgresql-simple, hasql, orville) provides an instance that maps queries to its native driver.

The instance also names the monad's schema and queue registry. The high-level API resolves table names and result types from them at compile time.

Associated Types

Source #type RegistryOf (m :: Type -> Type) :: JobPayloadRegistry

This monad's registry. The default reports an instance that omits it.

type RegistryOf (m :: Type -> Type) = TypeError ((('Text "No registry declared for " ':<>: 'ShowType m) ':$$: 'Text "Its MonadArbiter instance is missing the RegistryOf definition.") ':$$: (('Text "Add to the instance: type RegistryOf " ':<>: 'ShowType m) ':<>: 'Text " = YourRegistry")) :: JobPayloadRegistry

Source #type Handler (m :: Type -> Type) job result

Backend-specific handler shape (e.g. Connection -> job -> m result). JobHandler instantiates it at one queue's job and result types.

Methods

Source #getSchema :: m SchemaName

The schema name for this monad's Arbiter tables.

Source #executeQuery :: Query a -> m [a]

Run a query and decode the result rows. The text, its parameters, and the decoder travel together in the Query.

Source #executeQueryPrepared :: Query a -> m [a]

executeQuery for a hot statement whose text is stable across calls. A backend may prepare it once per connection.

Source #executeStatement :: Query a -> m Int64

Run a statement, returning the number of affected rows. The Query decoder is ignored.

Source #withDbTransaction :: m a -> m a

Run an action in a transaction. Nesting creates savepoints.

Source #runHandlerWithConnection :: JobHandler m payload (ResultOf m payload) -> JobRead payload -> m (ResultOf m payload)

Run a job handler with a database connection from the pool.

Source #getListener :: m (Maybe Listener)

The env's shared LISTEN/NOTIFY listener, or Nothing for poll-only.

Source #type JobHandler (m :: Type -> Type) payload result = Handler m (JobRead payload) result

A handler for payload's queue. result is what its registry entry declares.

Source #type HasRegistry (m :: Type -> Type) (registry :: JobPayloadRegistry) = (MonadArbiter m, RegistryOf m ~ registry)

MonadArbiter with the registry named, for signatures that mention it.

Source #type ResultOf (m :: Type -> Type) payload = ResultFor payload (RegistryOf m)

The result type declared by payload's registry entry. It is not injective. A signature naming it needs another argument to determine payload.

Source #type Params = [SomeParam]

Positional query parameters.

Source #data SomeParam where

An existentially-typed parameter. A ParamType paired with its value.

Constructors

SomeParam :: forall a. ParamType a -> a -> SomeParam 

Source #data ParamType a where

How a parameter is shaped: scalar, nullable, or array.

Constructors

PScalar :: forall a. Col a -> ParamType a 
PNullable :: forall a1. Col a1 -> ParamType (Maybe a1) 
PArray :: forall a1. Col a1 -> ParamType [a1] 
PNullArray :: forall a1. Col a1 -> ParamType [Maybe a1] 

Source #data Query a

A parameterized query paired with the decoder for its result rows.

Constructors

Query 

Fields

Instances

Instances details
Functor Query Source # 
Instance details

Defined in Arbiter.Core.Sql.Query

Methods

#fmap :: (a -> b) -> Query a -> Query b

#(<$) :: a -> Query b -> Query a

ToFragment (Query ()) Source # 
Instance details

Defined in Arbiter.Core.Sql.Query

Methods

Source #toFragment :: Query () -> Query ()

Monoid (Query ()) Source # 
Instance details

Defined in Arbiter.Core.Sql.Query

Methods

#mempty :: Query ()

#mappend :: Query () -> Query () -> Query ()

#mconcat :: [Query ()] -> Query ()

Semigroup (Query ()) Source #

Concatenation is defined for Query (), a fragment with text and parameters and no output columns.

Instance details

Defined in Arbiter.Core.Sql.Query

Methods

#(<>) :: Query () -> Query () -> Query ()

#sconcat :: NonEmpty (Query ()) -> Query ()

#stimes :: Integral b => b -> Query () -> Query ()