serve and (crate features serve-history-postgres or serve-history-sqlite) only.Expand description
Shared SQL run-history machinery for the Postgres and SQLite backends
(Phase 5, #127). Both backends are identical except for the connection setup
and the placeholder dialect ($n vs ?), so the schema, prepared-statement
text, pure helpers, and the entire RunHistory impl live here once and are
instantiated for each concrete sqlx pool via the impl_sql_history! macro.
Portability: every column is TEXT (timestamps are stored as fixed-width
RFC3339 with nanosecond precision + Z, which sorts lexicographically in
chronological order, so keyset pagination and expiry comparisons work without
any database date type — and thus without the sqlx chrono feature). The
whole RunRecord is serialized into the body column (the source of truth on
read); the dedicated columns exist only for filtering, ordering, and expiry.
Idempotency lives in a separate faucet_serve_idem table whose key
primary key is the required unique index (spec §10/§11). The claim is atomic
via INSERT … ON CONFLICT DO NOTHING plus an optimistic, expiry-guarded
takeover UPDATE, mirroring the memory backend’s shard-locked semantics.
Structs§
- Stmts
- Prepared-statement text for a backend, built once per dialect at connect time.
Enums§
- Dialect
- SQL placeholder dialect.
Constants§
- CLAIM_
ATTEMPTS - Bounded retry count for the atomic idempotency claim (handles a claim being purged concurrently between the insert attempt and the read-back).
- DDL
- DDL run at connect time. Valid verbatim on both Postgres and SQLite (only
TEXTcolumns,IF NOT EXISTS, and standard indexes).
Functions§
- decode_
body - encode_
body - fmt_ts
- Fixed-width RFC3339 (nanoseconds +
Z) — lexicographically sortable. - is_
expired - True when a claim timestamped
claimed_at(RFC3339) is older thanwindow. An unparseable or future timestamp is treated as not expired (safe: it won’t be silently re-claimed). - parse_
status - threshold
- RFC3339 timestamp
windowbeforenow(the purge / expiry threshold).