arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.MonadArbiter

Description

The database primitives every backend implements.

Synopsis

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.

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

data Query aSource #

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

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

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 ()#

data PieceSource #

One run of literal SQL or one parameter hole.

Constructors

Lit !Text

Literal SQL text.

Hole

A parameter hole.

Instances

Instances details
Eq Piece Source # 
Instance details

Defined in Arbiter.Core.Sql.Query

Methods

(==) :: Piece -> Piece -> Bool#

(/=) :: Piece -> Piece -> Bool#

Show Piece Source # 
Instance details

Defined in Arbiter.Core.Sql.Query

mkQuery :: [Piece] -> Params -> RowCodec a -> Query aSource #

A query from its pieces, parameters and decoder.

type Params = [SomeParam]Source #

Positional query parameters.

data SomeParam whereSource #

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

Constructors

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

data ParamType a whereSource #

Parameter shape: 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] 

type RowCodec = Ap NullColSource #

Free applicative over NullCol. Backends interpret this into their native row parser by pattern-matching on each NullCol.

data Col a whereSource #

Scalar PostgreSQL column type. The GADT tag recovers the Haskell type.

Constructors

CInt4 :: Col Int32 
CInt8 :: Col Int64 
CText :: Col Text 
CBool :: Col Bool 
CTimestamptz :: Col UTCTime 
CJsonb :: Col Value 
CStored :: forall payload. Col (Stored payload) 
CFloat8 :: Col Double 
CUuid :: Col UUID 

data NullCol a whereSource #

A named column with nullability. Carries the column name for backends that use name-based decoding, such as Orville.

Constructors

NotNull :: forall a. Text -> Col a -> NullCol a 
Nullable :: forall a1. Text -> Col a1 -> NullCol (Maybe a1) 

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 

Instances

Instances details
FromJSON (Stored payload) Source # 
Instance details

Defined in Arbiter.Core.Job.Types.Internal

Methods

parseJSON :: Value -> Parser (Stored payload)#

parseJSONList :: Value -> Parser [Stored payload]#

omittedField :: Maybe (Stored payload)#

ToJSON (Stored payload) Source #

The bytes are emitted as they are. toJSON has to parse them back.

Instance details

Defined in Arbiter.Core.Job.Types.Internal

Methods

toJSON :: Stored payload -> Value#

toEncoding :: Stored payload -> Encoding#

toJSONList :: [Stored payload] -> Value#

toEncodingList :: [Stored payload] -> Encoding#

omitField :: Stored payload -> Bool#

Eq (Stored payload) Source # 
Instance details

Defined in Arbiter.Core.Job.Types.Internal

Methods

(==) :: Stored payload -> Stored payload -> Bool#

(/=) :: Stored payload -> Stored payload -> Bool#

Show (Stored payload) Source # 
Instance details

Defined in Arbiter.Core.Job.Types.Internal

Methods

showsPrec :: Int -> Stored payload -> ShowS#

show :: Stored payload -> String#

showList :: [Stored payload] -> ShowS#

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.

queryAny :: MonadArbiter m => Query Bool -> m BoolSource #

Run a boolean Query. The result is true when a row is true.