| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core.MonadArbiter
Contents
Description
The database primitives every backend implements.
Synopsis
- class MonadUnliftIO m => MonadArbiter (m :: Type -> Type) where
- type RegistryOf (m :: Type -> Type) :: JobPayloadRegistry
- type Handler (m :: Type -> Type) job result
- getSchema :: m SchemaName
- executeQuery :: Query a -> m [a]
- executeQueryPrepared :: Query a -> m [a]
- executeStatement :: Query a -> m Int64
- withDbTransaction :: m a -> m a
- runHandlerWithConnection :: JobHandler m payload (ResultOf m payload) -> JobRead payload -> m (ResultOf m payload)
- getListener :: m (Maybe Listener)
- type JobHandler (m :: Type -> Type) payload result = Handler m (JobRead payload) result
- type HasRegistry (m :: Type -> Type) (registry :: JobPayloadRegistry) = (MonadArbiter m, RegistryOf m ~ registry)
- type ResultOf (m :: Type -> Type) payload = ResultFor payload (RegistryOf m)
- data Query a = Query {}
- data Piece
- mkQuery :: [Piece] -> Params -> RowCodec a -> Query a
- type Params = [SomeParam]
- data SomeParam where
- data ParamType a where
- type RowCodec = Ap NullCol
- data Col a where
- data NullCol a where
- runCodec :: Applicative f => (forall x. NullCol x -> f x) -> RowCodec a -> f a
- newtype Stored payload = Stored ByteString
- storedBytes :: Stored payload -> ByteString
- countOr0 :: MonadArbiter m => Query Int64 -> m Int64
- countOr0Prepared :: MonadArbiter m => Query Int64 -> m Int64
- queryMaybe :: MonadArbiter m => Query a -> m (Maybe a)
- queryAny :: MonadArbiter m => Query Bool -> m Bool
Documentation
class MonadUnliftIO m => MonadArbiter (m :: Type -> Type) whereSource #
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.
Minimal complete definition
getSchema, executeQuery, executeStatement, withDbTransaction, runHandlerWithConnection, getListener
Associated Types
type RegistryOf (m :: Type -> Type) :: JobPayloadRegistrySource #
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
type Handler (m :: Type -> Type) job resultSource #
Backend-specific handler shape (for example Connection -> job -> m result).
JobHandler instantiates it at one queue's job and result types.
Methods
getSchema :: m SchemaNameSource #
The schema name for this monad's arbiter tables.
executeQuery :: Query a -> m [a]Source #
Run a query and decode the result rows. The text, its parameters, and the
decoder travel together in the Query.
executeQueryPrepared :: Query a -> m [a]Source #
executeQuery for a hot statement whose text is stable across calls. A
backend may prepare it once per connection.
executeStatement :: Query a -> m Int64Source #
Run a statement, returning the number of affected rows. The Query
decoder is ignored.
withDbTransaction :: m a -> m aSource #
Run an action in a transaction. Nesting creates savepoints.
runHandlerWithConnection :: JobHandler m payload (ResultOf m payload) -> JobRead payload -> m (ResultOf m payload)Source #
Run a job handler in the backend's handler shape.
getListener :: m (Maybe Listener)Source #
The env's shared LISTEN/NOTIFY listener, or Nothing for poll-only.
type JobHandler (m :: Type -> Type) payload result = Handler m (JobRead payload) resultSource #
A handler for payload's queue. result is what its registry entry declares.
type HasRegistry (m :: Type -> Type) (registry :: JobPayloadRegistry) = (MonadArbiter m, RegistryOf m ~ registry)Source #
MonadArbiter with the registry named, for signatures that mention it.
type ResultOf (m :: Type -> Type) payload = ResultFor payload (RegistryOf m)Source #
The result type declared by payload's registry entry. It is not injective.
A signature naming it needs another argument to determine payload.
Instance kit
A parameterized query paired with the decoder for its result rows.
Constructors
| Query | |
Instances
One run of literal SQL or one parameter hole.
mkQuery :: [Piece] -> Params -> RowCodec a -> Query aSource #
A query from its pieces, parameters and decoder.
An existentially-typed parameter. A ParamType paired with its value.
Scalar PostgreSQL column type. The GADT tag recovers the Haskell type.
A named column with nullability. Carries the column name for backends that use name-based decoding, such as Orville.
runCodec :: Applicative f => (forall x. NullCol x -> f x) -> RowCodec a -> f aSource #
Interpret a RowCodec by providing a natural transformation
from NullCol to some Applicative.
newtype Stored payloadSource #
A payload as the JSON bytes the database holds. The type it decodes to is a phantom.
Constructors
| Stored ByteString |
storedBytes :: Stored payload -> ByteStringSource #
The JSON bytes of a stored payload.
Internal
Internal to the arbiter packages. Not covered by the PVP.
countOr0 :: MonadArbiter m => Query Int64 -> m Int64Source #
Run a single-row count Query, returning 0 on an empty or unexpected result.
countOr0Prepared :: MonadArbiter m => Query Int64 -> m Int64Source #
countOr0 over a prepared statement.
queryMaybe :: MonadArbiter m => Query a -> m (Maybe a)Source #
Run a Query and keep its first row.