Expand description
The one place either driver is named, and the reason the SQL is written once.
Every statement in this crate is a runtime sqlx::query in a dialect both
SQLite and PostgreSQL accept: epoch-second integers rather than dates, no
strftime/julianday/CAST/||, ON CONFLICT … DO NOTHING rather than
INSERT OR IGNORE, and RETURNING where a write has to read itself back.
What is not shared is the parameter marker, the row type and the pool
type, and this module is the whole of that seam: Query carries the SQL
and its Values until an Exec says which driver is on the other end,
Row hides which row came back, and Builder replaces
sqlx::QueryBuilder for the paged listings.
§Placeholders
Statements are written with ?, as they always were, and
to_dollar_placeholders rewrites them to $1…$n on the way to
PostgreSQL. Writing $n in the source would have worked on both — sqlx’s
SQLite driver parses a $N marker and binds argument N
(sqlx-sqlite/src/arguments.rs) — but every number would then be a hand-
maintained constant, and three things here build SQL by concatenation: the
live_certificate! predicate spliced into the middle of three statements,
the IN (?, ?, …) lists expanded per element, and the format!ed
fragments in job::claim_next and job::settle. One rewrite at the edge is
the same answer for all of them, and it cannot drift.
The rewrite deliberately skips '…' string literals. No statement in this
crate holds a ? inside one today; a test pins that the rewriter would
survive it if one arrived.
§Adding a bound type
Value has six variants because six are what the schema holds. A new one
means a variant, a Bind impl and an arm in each of the two encoders —
and, if it is read back, a Decode impl. Prefer reusing one: a JSON
column is bound and read as Value::Text, and a status enum as its
as_str.
Structs§
- Builder
sqlx::QueryBuilder’s job, overValuerather than one driver.- Query
- A statement and its parameters, before either driver has seen it.
- Query
Result - What a write reports back. A thin wrapper so a call site reads the same whichever driver ran it.
- Separated
- A comma-separated run of bound values, handed out by
Builder::separated.
Enums§
- Dialect
- Which dialect is on the other end of a connection.
- Exec
- Where a statement is about to run.
- Idx
- A column, named or positional.
- Null
Kind - The type an absent value would have had. See
Value::Null. - Row
- One row, from whichever driver produced it.
- Value
- One bound parameter, in the only six shapes this schema stores.
Traits§
- Bind
- What
Query::bindaccepts. - Decode
- What
Row::try_getcan read back.
Functions§
- is_
check_ violation - Was this error a
CHECKconstraint refusing the write? - is_
foreign_ key_ violation - Was this error a foreign key refusing the write? See
is_check_violation. - is_
unique_ violation - Was this error any unique constraint refusing the write?
- is_
unique_ violation_ on - Was this error a unique-violation on one particular constraint?
- query
- Starts a statement. The SQL is written with
?markers. - to_
dollar_ placeholders - Rewrites
?markers to$1…$n, leaving'…'literals alone.