Rindle docs and package mapSkip to main content

Module query_builder

Module query_builder 

Source
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§

ColumnDef
Static, build-time column metadata (spec 05 §4.1). The ONLY place a column name lives; the index into a &[ColumnDef] IS the [ColId]. optional drives the start-bound nullable-aware = vs IS / <,> vs (… IS NULL OR …) lowering (§3.7); ty drives the value boundary (to_sqlite_param and the leaf’s col() conversion).
CompiledQuery
The compiled statement: SQL text (the statement-cache key) + ordered bind params (the ? slots, in textual order).

Enums§

SqliteParam
A value already converted to its SQLite storage form (toSQLiteType, §3.13): boolInt(0|1), jsonText(serialized), else passthrough. Carries a distinct Null (the SQL NULL) separate from a Text("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 parameterized SELECT. 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 and params stay aligned (05 §4.4).
to_sqlite_param
toSQLiteType (query-builder.ts:278): convert a cell value to its SQLite bind form, ty-directed. booleannull stays NULL else 1/0; number/string/null pass 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().