| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core.Codec
Description
Typed encoding and decoding for PostgreSQL queries.
RowCodec— a free applicative that describes how to decode result rows. Each backend interprets it natively (postgresql-simple positional fields, hasql typed decoders, orville named marshallers).Params— a list of typed parameters for query execution. EachSomeParampairs aParamTypewith its value, letting backends encode without an untyped intermediary.
Both sides are built from the same Col GADT, ensuring type consistency
between what we send and what we read back.
Synopsis
- data Col a where
- data NullCol a where
- type RowCodec = Ap NullCol
- col :: Text -> Col a -> RowCodec a
- ncol :: Text -> Col a -> RowCodec (Maybe a)
- pureVal :: a -> RowCodec a
- runCodec :: Applicative f => (forall x. NullCol x -> f x) -> RowCodec a -> f a
- codecColumns :: RowCodec a -> [Text]
- data ParamType a where
- data SomeParam where
- type Params = [SomeParam]
- pval :: Col a -> a -> SomeParam
- pnul :: Col a -> Maybe a -> SomeParam
- parr :: Col a -> [a] -> SomeParam
- pnarr :: Col a -> [Maybe a] -> SomeParam
- jobRowCodec :: Text -> RowCodec (Job Value Int64 Text UTCTime)
- dlqRowCodec :: Text -> RowCodec (Int64, UTCTime, Job Value Int64 Text UTCTime)
- countCodec :: RowCodec Int64
- statsRowCodec :: RowCodec (Int64, Int64, Maybe Double)
Column types
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 (e.g. orville).
Row decoding
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
An existentially-typed parameter: a ParamType paired with its value.