COALESCE(col_a, col_b, ...) <op> <value> — left-hand expression
is the first non-null among the listed columns; right-hand side is
a bound value via the usual FilterValue envelope. Lets schemas
express the “ranked-fallback compare” pattern that shows up in
outbox / scheduler tables, where a single row carries several
time columns and the dispatcher wants the earliest non-null one.
A single migration step. The runner applies any rows not yet
present in cratestack_migrations. down is recorded but never
called — irreversible-by-default is the safe banking posture.
Result of a .select(...)-projected read. Holds the model with
only the selected columns populated — non-selected fields carry
their type’s Default::default() value ("" for String, 0
for integers, None for Option<T>, etc.).
Typed handle for an .include(...) call on a query builder. Carries
everything the runtime needs to issue the side-load query for a
to-one relation: a function pointer that extracts the FK value from
a parent row, and a static descriptor of the related model.
Conflict target for an upsert. Defaults to the model’s primary key
(matching the previous PK-only behavior). Columns lets callers
upsert on an arbitrary unique tuple — most commonly a natural key
that’s distinct from the PK (e.g. (owner_id, provider) on a
per-owner-and-provider settings row, or (pairing_id, slot) on a
per-slot envelope).
Where NULLs sort relative to non-NULL values. PostgreSQL’s default is
NULLS LAST for ASC and NULLS FIRST for DESC; SQLite’s default
is NULLS FIRST for both. CrateStack pins the framework default to
NULLS LAST so listings stay deterministic across backends and so
soft-deleted rows (typed Option<DateTime> that surface as None
for visible rows) don’t muscle their way to the top of every listing.
Override per-clause via OrderClause::nulls_first when scheduler /
outbox queries want fresh-as-null tasks at the head of the queue.
PostGIS spatial filter primitives. v1 ships two ops that cover the
“is point inside this zone” / “is this point within radius of that
zone” cases — the rest of the ST_* surface can land on demand.
DDL for the audit log table. Banks typically run migrations
through their own tooling — this DDL is exposed so the
crate::SqlxRuntime can idempotently ensure the table exists
during bootstrap.
Companion to sqlx::FromRow that decodes a row projected by
.select(...) — i.e. a row where only the named columns are
present in the SQL SELECT list. Non-selected fields populate to
their type’s Default::default() value.
Anything that can name a single SQL column. Lets coalesce
accept both bare &'static str column names and typed
FieldRef handles, so callers don’t have to choose between
schema-rooted typing and ad-hoc strings at the call site.
Accessor for a model’s primary key. Implemented by the macro on every
generated model struct so the batch operations can pair returned rows
back to the position of their input PK in the request, producing a
BatchItemResult with the right index and a NotFound entry for any
requested PK that didn’t come back.
Input shape for the upsert primitive — INSERT … ON CONFLICT (<pk>) DO UPDATE …. sql_values() must include the primary-key column (so the
backend can target the conflict), and primary_key_value() exposes the
PK separately so the runtime can issue a SELECT … FOR UPDATE before
the upsert to drive Created vs. Updated event / audit semantics.
Apply every pending migration in the input slice in order. Each
runs in its own transaction; checksum drift aborts the whole apply
(banks treat drift as a release-process failure for humans, not a
silent overwrite).
Build a COALESCE(...) left-hand operand. The returned
CoalesceExpr carries the column list; chain a comparator
method (.lte, .eq, .is_null, …) to produce a FilterExpr
the query builders can consume.
Compute when a record originally captured at created_at will
expire. Pulled out for unit-test reach; the SystemTime arithmetic
is otherwise awkward to assert against without a clock injection
point.
Geographic point (WGS-84 lng/lat). The naming follows the PostGIS
ST_MakePoint(x, y) convention — lng is the X axis (longitude),
lat is the Y axis (latitude). Don’t accidentally swap them;
the engine has no way to detect it and your filter will silently
match points across the world.
Extract the primary-key field from a serialized model snapshot.
Used to stamp audit events with a stable identifier even when the
schema doesn’t surface the PK column verbatim in the response.
Begin a transaction at the requested isolation level, run body against
the live transaction, and commit. On 40001 (serialization_failure) or
40P01 (deadlock_detected) the transaction is rolled back and the body
runs again, up to MAX_RETRIES_DEFAULT times. Other errors propagate
immediately.
Same as run_in_isolated_tx but with a caller-chosen retry budget.
Banks running long-tail contended writes sometimes want a higher cap
(5–10); single-row CAS workflows can drop to 1 to fail fast.
Convert a model into the JSON snapshot used by the audit log.
Returns None if the model isn’t serializable; that should never
happen for generated models which derive Serialize.
Inspect each migration in migrations against cratestack_migrations
and report which are pending / applied / drifted. Use before apply to
surface drift to the operator without changing state.