Struct Schema
pub struct Schema {
pub columns: Vec<Box<str>>,
pub column_types: Vec<ValueType>,
pub primary_key: Vec<usize>,
pub sort: Vec<(usize, bool)>,
pub relationships: Vec<RelDef>,
pub singular: bool,
pub projection: Option<Vec<usize>>,
}Expand description
The view / pipeline schema: a table’s columns + key + sort plus the
per-query relationship slots and .one() shape the dataflow and materialized
view carry. A source table is registered with the lighter SourceSchema
(no relationships, no singular); the build path widens that to a Schema and
fills relationships from the query AST — never from a source declaration, of
which there are none.
Fields§
§columns: Vec<Box<str>>Column names. Owned (Vec<Box<str>>) so a runtime-supplied schema (the JS
wasm boundary, WS01.3) can construct it without leaking Box::leak’d
'static strings. Schema::new still takes Vec<&str>, so existing
vec!["id", …] literal call sites coerce in unchanged.
column_types: Vec<ValueType>Declared logical column types, parallel to columns (design 226 §4.1).
Schema::new defaults every column to ValueType::Number — the
untyped/legacy declaration; homes that know the real types (the SQLite
replica’s decltype discovery, the SQLite leaf’s ColumnDefs) install them
via Schema::with_column_types. The engine consults these only for
exact-integer behavior, so a defaulted non-numeric column is inert — the
value boundary keeps its own per-leaf typing channel.
primary_key: Vec<usize>§sort: Vec<(usize, bool)>§relationships: Vec<RelDef>Declared outgoing relationships (slot = list index). Empty for a leaf table
that is never a join parent. A join resolves its rel_name to a slot here
at build time (Schema::rel_slot), so the hot path is index-addressed.
singular: bool.one() shape for this level of the materialized view — lowered from the
query’s Ast::one by view_schema.
When set, the result boundary presents this level as a single object (or
null/absent) instead of an array; the engine tree itself stays plural at
every level. Always false for a source / table schema.
projection: Option<Vec<usize>>Projection (PROJECTION-SUPPORT-DESIGN.md §6). None ⇒ the view reports
every column ('*'); Some(cols) ⇒ the view reports only these base
ColIds, in this order — the lowering of the query’s
Ast::select. columns stays the full, positional column
list (rows are full width everywhere on the client, §2.1); projection is
applied only at the result boundary (the marshal reads columns[col] / row[col]
for each col in this list). The PK / sort indices therefore remain valid in
the full column space regardless of what the view reports.
Implementations§
§impl Schema
impl Schema
pub fn new(
columns: Vec<&str>,
primary_key: Vec<usize>,
sort: Vec<(usize, bool)>,
) -> Schema
pub fn new( columns: Vec<&str>, primary_key: Vec<usize>, sort: Vec<(usize, bool)>, ) -> Schema
Construct a relationship-free schema (the common case). Use
Schema::with_relationships to declare relationships for a join parent.
Keeps the 3-field call sites terse now that relationships exists.
pub fn with_relationships(self, relationships: Vec<RelDef>) -> Schema
pub fn with_relationships(self, relationships: Vec<RelDef>) -> Schema
Builder: declare this table’s outgoing relationships (slot = list index).
pub fn with_column_types(self, column_types: Vec<ValueType>) -> Schema
pub fn with_column_types(self, column_types: Vec<ValueType>) -> Schema
Builder: install the declared column types (parallel to columns, design
226 §4.1), replacing Schema::new’s all-Number default.
pub fn rel_child(&self, slot: RelId) -> Option<&Schema>
pub fn rel_child(&self, slot: RelId) -> Option<&Schema>
The target Schema of relationship slot, or None if the slot is
undeclared or join-only (no child schema attached).