arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.Codec

Description

Internal to the arbiter packages. Not covered by the PVP.

Typed encoding and decoding for PostgreSQL queries.

  • RowCodec decodes result rows. It is a free applicative that each backend (postgresql-simple, hasql, Orville) interprets natively.
  • Params is the typed parameter list for query execution.

Both use the same Col GADT.

Synopsis

Column types

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) 

Row decoding

type RowCodec = Ap NullColSource #

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

col :: Text -> Col a -> RowCodec aSource #

A non-nullable column.

ncol :: Text -> Col a -> RowCodec (Maybe a)Source #

A nullable column.

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.

codecColumns :: RowCodec a -> [Text]Source #

Extract the column names from a codec (in order).

joinColumns :: [Text] -> TextSource #

Column names as a comma-separated SQL list.

Parameter encoding

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] 

data SomeParam whereSource #

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

Constructors

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

type Params = [SomeParam]Source #

Positional query parameters.

pval :: Col a -> a -> SomeParamSource #

A non-null scalar parameter.

pnul :: Col a -> Maybe a -> SomeParamSource #

A nullable scalar parameter.

parr :: Col a -> [a] -> SomeParamSource #

A non-null array parameter.

pnarr :: Col a -> [Maybe a] -> SomeParamSource #

An array parameter with nullable elements.

Bidirectional job write codec

data Codec s aSource #

A profunctor codec. Writes source s to INSERT columns and params, decodes value a back.

Instances

Instances details
Applicative (Codec s) Source # 
Instance details

Defined in Arbiter.Core.Codec

Methods

pure :: a -> Codec s a#

(<*>) :: Codec s (a -> b) -> Codec s a -> Codec s b#

liftA2 :: (a -> b -> c) -> Codec s a -> Codec s b -> Codec s c#

(*>) :: Codec s a -> Codec s b -> Codec s b#

(<*) :: Codec s a -> Codec s b -> Codec s a#

Functor (Codec s) Source # 
Instance details

Defined in Arbiter.Core.Codec

Methods

fmap :: (a -> b) -> Codec s a -> Codec s b#

(<$) :: a -> Codec s b -> Codec s a#

cColumns :: Codec s a -> [(Text, Text)]Source #

Writable (column name, PostgreSQL type) pairs, in order.

cScalar :: Codec s a -> s -> ParamsSource #

Single-row parameters, one per column.

cArray :: Codec s a -> [s] -> ParamsSource #

Batch parameters, one array per column.

jobCodec :: Text -> Codec (JobWriteSource payload) (JobRead (Stored stored))Source #

Main-table codec over a JobWriteSource.

payloadWriteCodec :: Codec (Value, PayloadColumns) PayloadKeysSource #

An encoded payload and the columns derived from it, as every job write stores them.

data JobWriteSource payloadSource #

The insert side of a job row. The payload encoding is built once by the caller.

Constructors

JobWriteSource 

Fields

writeColumnNames :: [Text]Source #

Writable job column names, in insert order.

Job codecs

jobRowCodec :: Text -> RowCodec (JobRead (Stored payload))Source #

Decoder for a main-table job row.

dlqRowCodec :: Text -> RowCodec (Int64, UTCTime, JobRead (Stored payload))Source #

DLQ envelope. The shared job snapshot plus its DLQ id and failure time.

archiveRowCodec :: Text -> RowCodec (Int64, UTCTime, JobRead (Stored payload), Maybe Value)Source #

Archive envelope. The shared job snapshot plus the result a completed root job stored.

Admission view codecs

rateLimitPolicyViewCodec :: RowCodec RateLimitPolicyViewSource #

A policy row with bucket aggregates and live throttled count.

rateLimitBucketCodec :: RowCodec RateLimitBucketViewSource #

A token-bucket row as the admin API reports it.

concurrencyPolicyViewCodec :: RowCodec ConcurrencyPolicyViewSource #

A concurrency policy row as the admin API reports it.

concurrencyKeyViewCodec :: RowCodec ConcurrencyKeyViewSource #

A per-key in-flight count as the admin API reports it.

Cron codecs

Worker codecs

workerRowWithHealthCodec :: RowCodec (WorkerRow, Text)Source #

Worker columns plus the raw derived health token. The operation layer validates the token before returning a WorkerRow.

Queue codecs

queueRowCodec :: RowCodec QueueRowSource #

An arbiter_queues row.