Skip to main content

Crate cratestack_sqlx

Crate cratestack_sqlx 

Source

Modules§

sqlx
Compatibility shim that exposes a sqlx-shaped API by re-exporting from sqlx-core + sqlx-postgres directly.

Structs§

Aggregate
AggregateColumn
AggregateCount
BatchCreate
BatchDelete
BatchGet
BatchUpdate
BatchUpsert
CoalesceExpr
Left-hand operand of a coalesce-based filter — chain a comparator method to turn it into a FilterExpr.
CoalesceFilter
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.
CreateDefault
CreateRecord
DeleteMany
DeleteRecord
FieldRef
Filter
FindMany
FindManyWith
FindUnique
JsonTextPath
Left-hand operand of a json_get_text filter — chain a comparison method (.eq, .lt, .is_null, …) to produce a FilterExpr.
Migration
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.
MigrationState
ModelColumn
ModelDelegate
ModelDescriptor
OrderClause
ProjectedFindMany
ProjectedFindUnique
Projection
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.).
ReadPolicy
RelationFilter
RelationInclude
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.
ScopedAggregate
ScopedAggregateColumn
ScopedAggregateCount
ScopedBatchCreate
ScopedBatchDelete
ScopedBatchGet
ScopedBatchUpdate
ScopedBatchUpsert
ScopedCreateRecord
ScopedDeleteMany
ScopedDeleteRecord
ScopedFindMany
ScopedFindManyWith
ScopedFindUnique
ScopedModelDelegate
ScopedProjectedFindMany
ScopedProjectedFindUnique
ScopedUpdateMany
ScopedUpdateManySet
ScopedUpdateRecord
ScopedUpdateRecordSet
ScopedUpsertRecord
SpatialPoint
Builder returned by crate::point for assembling a spatial filter. Holds nothing but the lat/lng pair until a comparator is chained.
SqlColumnValue
SqlxIdempotencyStore
SqlxRuntime
UpdateMany
UpdateManySet
UpdateRecord
UpdateRecordSet
UpsertRecord

Enums§

ConflictTarget
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).
CreateDefaultType
FilterExpr
FilterOp
JsonFilter
JSON / JSONB filter predicates. Two flavors:
MigrationStatus
NullOrder
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.
PolicyExpr
PolicyLiteral
ReadPredicate
RelationQuantifier
SortDirection
SpatialFilter
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.
SqlValue

Constants§

AUDIT_TABLE_DDL
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.
MIGRATIONS_TABLE_DDL

Traits§

CreateModelInput
FromPartialPgRow
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.
IntoColumnName
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.
IntoSqlValue
ModelPrimaryKey
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.
UpdateModelInput
UpsertModelInput
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.

Functions§

apply_pending
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).
coalesce
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.
create_record_with_executor
ensure_migrations_table
expiry_from
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.
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.
primary_key_from_snapshot
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.
run_in_isolated_tx
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.
run_in_isolated_tx_with_retries
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.
snapshot_model
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.
status
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.
update_record_with_executor

Type Aliases§

BatchUpdateItem
One per-item update: (id, patch, optional expected version).