arbiter-core-0.1.0.0: Core types and logic for PostgreSQL-backed job queue
Safe HaskellNone
LanguageGHC2024

Arbiter.Core.Codec

Description

Typed encoding and decoding for PostgreSQL queries.

  • RowCodec - free applicative for decoding result rows. Each backend (postgresql-simple, hasql, orville) interprets it natively.
  • Params - typed parameter list for query execution.

Both use the same Col GADT, keeping encode and decode types in sync.

Synopsis

Column types

data Col a where Source #

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 
CFloat8 :: Col Double 

data NullCol a where Source #

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

type RowCodec = Ap NullCol Source #

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

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

A non-nullable column.

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

A nullable column.

pureVal :: a -> RowCodec a Source #

Inject a pure value (not read from the database).

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

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).

Parameter encoding

data ParamType a where Source #

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] 

data SomeParam where Source #

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 -> SomeParam Source #

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

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

Job codecs

Cron codecs