Skip to main content

Module read_model_store

Module read_model_store 

Source
Expand description

§Postgres Read Model Store

Implementation of ReadModelStore backed by an sqlx::PgPool. Mirrors the SQLite store’s contract: every projection table has the standard projection shape (id TEXT PK, version BIGINT, data JSONB), and writes are version-gated so replay and at-least-once delivery converge.

§Idempotency

upsert translates to

INSERT INTO {table} (id, version, data) VALUES ($1, $2, $3)
ON CONFLICT (id) DO UPDATE
   SET version = EXCLUDED.version, data = EXCLUDED.data
 WHERE {table}.version < EXCLUDED.version

Applying an older or equal version never regresses state.

§Queries

find_by uses Postgres’ data ->> $field text-extraction operator. IS NOT DISTINCT FROM gives null-safe equality.

§Identifiers

sqlx binds values, not identifiers. Table names are spliced into SQL, so they are validated against [A-Za-z0-9_] first ([check_ident]). Field names are bound as the ->> operand and so are parameterized, but are still validated for parity with the SQLite store.

Structs§

PostgresReadModelStore
Postgres implementation of ReadModelStore.