Expand description
build_select_query — the FetchRequest → parameterized SELECT lowering
(spec 05 §4.4). A faithful port of packages/zqlite/src/query-builder.ts.
All identifiers come from the schema (resolved from a [ColId] to a
ColumnDef::name); all values are bound ? params, never interpolated
— the JS uses @databases/sql tagged templates, we emit ? placeholders and a
parallel SqliteParam vec. The ? slots and the param vec are built in
lockstep, so the emission order IS the bind order (05 §4.4): constraint →
multiConstraints → start → filters (ORDER BY has no params).
Every cell value crosses the to_sqlite_param boundary (toSQLiteType,
query-builder.ts:278): boolean→0/1 (a null boolean stays NULL), json→
serialized TEXT (a null json becomes the 4-char TEXT "null" — the three SQL
nulls are distinct, 05 §3.13 / §13 Q11). Strings/numbers/null pass through.
Scope (per 05 §1.2): this lowers the already-subquery-stripped
SqlCondition. Statics must have been substituted upstream — a static
operand is a builder bug, not a runtime path (debug_assert!-style
unreachable, foundations §10). Here statics simply don’t exist in the
[Operand] enum, which makes that invariant structural.
Structs§
- Column
Def - Static, build-time column metadata (spec
05§4.1). The ONLY place a column name lives; the index into a&[ColumnDef]IS the [ColId].optionaldrives the start-bound nullable-aware=vsIS/<,>vs(… IS NULL OR …)lowering (§3.7);tydrives the value boundary (to_sqlite_paramand the leaf’scol()conversion). - Compiled
Query - The compiled statement: SQL text (the statement-cache key) + ordered bind
params (the
?slots, in textual order).
Enums§
- Sqlite
Param - A value already converted to its SQLite storage form (
toSQLiteType, §3.13):bool→Int(0|1),json→Text(serialized), else passthrough. Carries a distinctNull(the SQL NULL) separate from aText("null")(a serialized json null) — the two SQL nulls the JS keeps distinct (05§13 Q11).
Functions§
- build_
select_ query - Lower a
FetchRequest’s pushed-down parts (+ connection filter + sort) to a parameterizedSELECT. The arg grouping is regrouped from the JS for readability; the clause-emission order is fixed (constraint → multiConstraints → start → filters → ORDER BY) so the?slots andparamsstay aligned (05§4.4). - to_
sqlite_ param toSQLiteType(query-builder.ts:278): convert a cell value to its SQLite bind form, ty-directed.boolean→nullstays NULL else1/0;number/string/nullpass through;json→ serialized TEXT (a null json serializes to the TEXT"null"). Takes the borrowed [Value] (a flat row’s cell form); owned callers bridge with.as_ref().