arbiter-core-0.1.0.0
arbiter-core
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.Codec

Description

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

Source #data Col a where

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

Source #data NullCol a where

A named column with nullability. Carries the column name for backends that use name-based decoding (e.g. orville).

Constructors

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

Row decoding

Source #type RowCodec = Ap NullCol

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

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

A non-nullable column.

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

A nullable column.

Source #runCodec :: Applicative f => (forall x. NullCol x -> f x) -> RowCodec a -> f a

Interpret a RowCodec by providing a natural transformation from NullCol to some Applicative.

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

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

Parameter encoding

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 SomeParam where

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

Constructors

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

Source #type Params = [SomeParam]

Positional query parameters.

Source #pval :: Col a -> a -> SomeParam

A non-null scalar parameter.

Source #pnul :: Col a -> Maybe a -> SomeParam

A nullable scalar parameter.

Source #parr :: Col a -> [a] -> SomeParam

A non-null array parameter.

Source #pnarr :: Col a -> [Maybe a] -> SomeParam

An array parameter with nullable elements.

Bidirectional job write codec

Source #data Codec s a

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

Source #cDecode :: Codec s a -> RowCodec a

The read side.

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

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

Source #cScalar :: Codec s a -> s -> Params

Single-row parameters, one per column.

Source #cArray :: Codec s a -> [s] -> Params

Batch parameters, one array per column.

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

Main-table codec. The write source contains public enqueue fields, payload columns, parent id, rollup state, and suspension state.

Source #data JobWriteSource payload

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

Source #writeColumnNames :: [Text]

Writable job column names, in insert order.

Job codecs

Source #jobRowCodec :: Text -> RowCodec (JobRead Value)

Decoder for a main-table job row.

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

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

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

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

Source #rateLimitPolicyViewCodec :: RowCodec RateLimitPolicyView

A policy row with bucket aggregates and live throttled count.

Source #rateLimitBucketCodec :: RowCodec RateLimitBucketView

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

Source #concurrencyPolicyViewCodec :: RowCodec ConcurrencyPolicyView

A pool policy row as the admin API reports it.

Source #concurrencyKeyViewCodec :: RowCodec ConcurrencyKeyView

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

Cron codecs

Worker codecs

Source #workerRowWithHealthCodec :: RowCodec (WorkerRow, Text)

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

Queue codecs

Source #queueRowCodec :: RowCodec QueueRow

An arbiter_queues row.