| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Core.Codec
Description
Internal to the arbiter packages. Not covered by the PVP.
Typed encoding and decoding for PostgreSQL queries.
RowCodecdecodes result rows. It is a free applicative that each backend (postgresql-simple, hasql, Orville) interprets natively.Paramsis the typed parameter list for query execution.
Both use the same Col GADT.
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)
- runCodec :: Applicative f => (forall x. NullCol x -> f x) -> RowCodec a -> f a
- codecColumns :: RowCodec a -> [Text]
- joinColumns :: [Text] -> 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
- data Codec s a
- cColumns :: Codec s a -> [(Text, Text)]
- cScalar :: Codec s a -> s -> Params
- cArray :: Codec s a -> [s] -> Params
- jobCodec :: Text -> Codec (JobWriteSource payload) (JobRead (Stored stored))
- payloadWriteCodec :: Codec (Value, PayloadColumns) PayloadKeys
- data JobWriteSource payload = JobWriteSource {
- sourceJob :: JobWrite payload
- sourceEncoded :: Value
- sourceColumns :: PayloadColumns
- sourceParentId :: Maybe Int64
- sourceParentState :: Maybe Value
- sourceSuspended :: Bool
- writeColumnNames :: [Text]
- jobRowCodec :: Text -> RowCodec (JobRead (Stored payload))
- dlqRowCodec :: Text -> RowCodec (Int64, UTCTime, JobRead (Stored payload))
- archiveRowCodec :: Text -> RowCodec (Int64, UTCTime, JobRead (Stored payload), Maybe Value)
- rateLimitPolicyViewCodec :: RowCodec RateLimitPolicyView
- rateLimitBucketCodec :: RowCodec RateLimitBucketView
- concurrencyPolicyViewCodec :: RowCodec ConcurrencyPolicyView
- concurrencyKeyViewCodec :: RowCodec ConcurrencyKeyView
- cronScheduleRowCodec :: RowCodec CronScheduleRow
- workerRowWithHealthCodec :: RowCodec (WorkerRow, Text)
- queueRowCodec :: RowCodec QueueRow
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, such as Orville.
Row decoding
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
An existentially-typed parameter. A ParamType paired with its value.
Bidirectional job write codec
A profunctor codec. Writes source s to INSERT columns and params, decodes value a back.
cColumns :: Codec s a -> [(Text, Text)]Source #
Writable (column name, PostgreSQL type) pairs, in order.
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
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
cronScheduleRowCodec :: RowCodec CronScheduleRowSource #
A cron_schedules row.
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.