Expand description
The typed query builder that zero-rust codegen generates code for: row
structs read from views, columns and relationships named by typed
constants, and Query, a typed wrapper of AnyQuery (Query in
packages/zql/src/query/query.ts).
The generated code holds a row struct per table with a Column
constant per column and a Relationship constant per relationship,
and a function per table that starts a query:
zql::issue()
.where_eq(Issue::STATUS, IssueStatus::Open)
.where_expr(|e| e.or(vec![Issue::PRIORITY.ge(2.0), Issue::ASSIGNEE_ID.eq(None)]))
.where_exists(Issue::LABELS, ExistsOptions::default(), |q| q.where_eq(Label::NAME, "bug".into()))
.related(Issue::COMMENTS, |q| q.order_by(Comment::CREATED, Direction::Desc).limit(10))
.order_by(Issue::MODIFIED, Direction::Desc)
.limit(50)A typed query builds the same AST as the AnyQuery calls with the
same names; Query::read reads a view of it as the query’s result
type. In a mutator, the generated mutate functions return a
TypedTableMutator per table, whose updates and deletes take the
generated <Row>Update and <Row>Key structs. The items marked “for generated code” are what the generated
from_entrys and value conversions call.
Re-exports§
pub use crate::ast::Condition;pub use crate::ast::Direction;pub use crate::ast::JsonPathSegment;pub use crate::ast::SimpleOperator;pub use crate::client::Transaction;pub use crate::ivm::ViewEntry;pub use crate::ivm::ViewValue;pub use crate::json::Object;pub use crate::json::Value;pub use crate::query::AnyGroupedQuery;pub use crate::query::AnyQuery;pub use crate::query::ExistsOptions;pub use crate::query::StaticParameter;pub use crate::schema::Schema;
Structs§
- Column
- A column of the row type
R, holdingVs: generated as a constant of the row struct, such asIssue::TITLE. - Column
Ref - A column of
Rof any type, for the lists ofgroup_by,distinctandstart_values:Issue::OWNER_ID.into(). - Distinct
Row - A row of
distinct(...): the values of its columns, read withDistinctRow::get. - Group
Row - A row of
group_by(...)and an aggregate: the group’s columns, read withGroupRow::get, and the aggregate’svalue. - Grouped
Query - A query grouped by columns, waiting for the aggregate that reduces each
group (
GroupedQueryinpackages/zql/src/query/query.ts): oneGroupRowper group. - Json
Path - A value inside a
jsoncolumn in awhere_expr. Its JSON type isn’t known, so it compares with anyValue: one of another type never equals it. Comparing with null usesIS. - Query
- A query over the rows of
R’s table that materializes to aT: the rows (Vec<R>), the row ofone()(Option<R>), or an aggregate. - Relationship
- A relationship from the row type
Rto the row typeD: generated as a constant of the row struct, such asIssue::COMMENTS. - Relationship
Aggregates - The aggregates a row’s query asked for in
related, by relationship:related(Issue::COMMENTS, |q| q.count())givesissue.aggregates.count(Issue::COMMENTS). The relationship’s own field staysNone. - RowExpression
- The row a
where_exprcondition is about: JSON paths into its columns,existsover its relationships, and the connectives. Compare columns with their constants’ methods, such asIssue::TITLE.like("%bug%"). - Typed
Table Mutator - The typed CRUD operations of a table in a mutator (
tx.mutate.<table>in JS), which the generatedmutatemodule returns: - Zero
Value Error - A value that doesn’t fit the Rust type a row declares for it.
Enums§
- Column
Update - A column in an update that can be null: left as it is (the default),
set to null, or set to a value. A column that can’t be null is an
Optionin an update instead,Noneleaving it.
Traits§
- Column
Values - Some of a row’s columns, by client column name: what an update or a delete writes. For generated code.
- Numeric
Zero Value - A column
sumandavgcan reduce: a number (NumericSelector). - Optional
Query Element - What an
Optionquery value holds: the row ofone(), or the value ofsum,avg,minormax, which isNoneover no rows. Generated rows implement it withoptional_row, generated enumerations withoptional_value. - Ordered
Zero Value - A column
minandmaxcan reduce: a number or a string, enumerations included (OrderedSelector).Unwrappedis the type of its non-null values, the aggregate’s type. - Query
Element - A row of a query’s result: a row struct, or a row of
group_byordistinct. - Query
Value - What a query materializes to: its rows (
Vec<Row>,Option<Row>afterone()), or the value of an aggregate, such as thei64ofcount(). - ZeroRow
- A row struct of a table, as
zero-rust codegengenerates it: the table’s columns as fields, and a field per relationship that a query fills when it asks for it withrelated. - Zero
Value - A Rust type a column holds. Generated row structs use these for their columns, and the query builder encodes compared values with them.
Functions§
- column
- A column of a row, for generated
from_entrys:indexis its position in the table’s schema, where the row has it unless it came from elsewhere. Reading it there skips looking the name up. - decode
- Reads
name’s value of a row or object, for generated code. Anullin a column that can’t be null reads asZeroValue::value_for_null. - field
- A field of a
json<T>()object; a missing one reads asnull, so only anOptiontakes it. - many
- A many relationship of a row, for generated
from_entrys:Nonewhen the query didn’t ask for its rows, also when it asked for an aggregate of them. - object
- The object a generated
json<T>()type reads its fields from. - one
- A one relationship of a row, for generated
from_entrys:Nonewhen the query didn’t ask for it or no row matches. - optional_
row - The row of a
one()view, for generated rows’OptionalQueryElement. - optional_
value - The value of an aggregate’s view:
Nonewhen it’s null. - schema_
from_ json - The schema of generated code, from the JSON form
Schema::from_jsonreads. Panics when it isn’t one, which generated code never is.