Skip to main content

Module typed

Module typed 

Source
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, holding Vs: generated as a constant of the row struct, such as Issue::TITLE.
ColumnRef
A column of R of any type, for the lists of group_by, distinct and start_values: Issue::OWNER_ID.into().
DistinctRow
A row of distinct(...): the values of its columns, read with DistinctRow::get.
GroupRow
A row of group_by(...) and an aggregate: the group’s columns, read with GroupRow::get, and the aggregate’s value.
GroupedQuery
A query grouped by columns, waiting for the aggregate that reduces each group (GroupedQuery in packages/zql/src/query/query.ts): one GroupRow per group.
JsonPath
A value inside a json column in a where_expr. Its JSON type isn’t known, so it compares with any Value: one of another type never equals it. Comparing with null uses IS.
Query
A query over the rows of R’s table that materializes to a T: the rows (Vec<R>), the row of one() (Option<R>), or an aggregate.
Relationship
A relationship from the row type R to the row type D: generated as a constant of the row struct, such as Issue::COMMENTS.
RelationshipAggregates
The aggregates a row’s query asked for in related, by relationship: related(Issue::COMMENTS, |q| q.count()) gives issue.aggregates.count(Issue::COMMENTS). The relationship’s own field stays None.
RowExpression
The row a where_expr condition is about: JSON paths into its columns, exists over its relationships, and the connectives. Compare columns with their constants’ methods, such as Issue::TITLE.like("%bug%").
TypedTableMutator
The typed CRUD operations of a table in a mutator (tx.mutate.<table> in JS), which the generated mutate module returns:
ZeroValueError
A value that doesn’t fit the Rust type a row declares for it.

Enums§

ColumnUpdate
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 Option in an update instead, None leaving it.

Traits§

ColumnValues
Some of a row’s columns, by client column name: what an update or a delete writes. For generated code.
NumericZeroValue
A column sum and avg can reduce: a number (NumericSelector).
OptionalQueryElement
What an Option query value holds: the row of one(), or the value of sum, avg, min or max, which is None over no rows. Generated rows implement it with optional_row, generated enumerations with optional_value.
OrderedZeroValue
A column min and max can reduce: a number or a string, enumerations included (OrderedSelector). Unwrapped is the type of its non-null values, the aggregate’s type.
QueryElement
A row of a query’s result: a row struct, or a row of group_by or distinct.
QueryValue
What a query materializes to: its rows (Vec<Row>, Option<Row> after one()), or the value of an aggregate, such as the i64 of count().
ZeroRow
A row struct of a table, as zero-rust codegen generates it: the table’s columns as fields, and a field per relationship that a query fills when it asks for it with related.
ZeroValue
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: index is 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. A null in a column that can’t be null reads as ZeroValue::value_for_null.
field
A field of a json<T>() object; a missing one reads as null, so only an Option takes it.
many
A many relationship of a row, for generated from_entrys: None when 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: None when 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: None when it’s null.
schema_from_json
The schema of generated code, from the JSON form Schema::from_json reads. Panics when it isn’t one, which generated code never is.

Type Aliases§

Grouped
A query of the GroupRows of group_by and an aggregate.