Expand description
Statement AST types for representing queries, inserts, updates, and deletes. Statement AST types for Toasty’s query compilation pipeline.
This module defines the abstract syntax tree (AST) for statements that
Toasty’s query engine processes. The top-level type is [Statement], which
represents one of four operations: [Query], [Insert], [Update], or
[Delete].
Statements exist at two layers:
- Model-level: references models, fields, and associations from the app schema. This is what user-facing code produces.
- Table-level: references tables, columns, and joins from the DB schema. This is what the query engine lowers model-level statements into before handing them to a database driver.
The query engine pipeline transforms statements through several phases: simplify, lower, plan, and execute. Types in this module appear throughout all phases.
§Examples
ⓘ
use toasty_core::stmt::{Statement, Query, Values};
// Create a simple values-based query statement
let query = Query::unit();
let stmt = Statement::Query(query);
assert!(stmt.is_query());Re-exports§
Modules§
Structs§
- Assignments
- An ordered map of field assignments for an
Updatestatement. - Association
- A reference to an association traversal from a source query.
- Condition
- A guard condition on an
Updatestatement. - Const
Input - An
Inputimplementation that resolves nothing. - Cte
- A common table expression (CTE) within a
Withclause. - Delete
- A
DELETEstatement that removes existing records. - Derived
Ref - A resolved reference into a derived table column.
- ExprAnd
- A logical “and” of multiple expressions.
- ExprAny
- Returns
trueif any item in a collection evaluates totrue. - ExprArg
- A positional argument placeholder.
- Expr
Binary Op - A binary operation between two expressions.
- Expr
Cast - A type cast expression.
- Expr
Column - A reference to a database column.
- Expr
Context - Provides schema-aware context for expression type inference and reference resolution.
- Expr
Error - An expression representing an unreachable branch.
- Expr
Exists - Tests whether a subquery returns any rows.
- Expr
InList - Tests whether a value is contained in a list.
- Expr
InSubquery - Tests whether a value is in the results of a subquery.
- Expr
IsNull - Tests whether an expression is null.
- Expr
IsVariant - Tests whether an expression evaluates to a specific enum variant.
- ExprLet
- A scoped binding expression with one or more bindings.
- Expr
List - A list of expressions.
- ExprMap
- A map/transform operation over a collection.
- Expr
Match - A match expression that dispatches on a subject expression.
- ExprNot
- Negates a boolean expression.
- ExprOr
- A logical “or” of multiple expressions.
- Expr
Project - Projects a field or element from a base expression.
- Expr
Record - A record of expressions.
- Expr
SetOp - A set operation combining multiple queries.
- Expr
Stmt - A statement used as an expression.
- Filter
- A
WHEREclause filter for statements. - Func
Count - The SQL
COUNTaggregate function. - Func
Last Insert Id - The
LAST_INSERT_ID()function expression (MySQL-specific). - Hash
Index - A unique hash index over a borrowed slice of
Values. - Insert
- An
INSERTstatement that creates new records. - Insert
Table - A lowered insert target specifying a database table and its columns.
- Join
- A join clause within a
TableWithJoins. - Limit
Cursor - Cursor-based pagination parameters.
- Limit
Offset - Traditional SQL
LIMIT … OFFSET …parameters. - Match
Arm - A single arm in a match expression.
- OrderBy
- An
ORDER BYclause containing one or more ordering expressions. - Order
ByExpr - A single expression within an
OrderByclause, with an optional sort direction. - Path
- A rooted field traversal path through the application schema.
- Path
Field Set - A set of field indices, backed by a bit set.
- Projection
- A sequence of field indices describing how to navigate into a nested value.
- Query
- A query statement that reads data from the database.
- Select
- A
SELECTexpression within a query body. - Sorted
Index - A sorted index over a borrowed slice of
Values. - Source
Model - A model-level data source.
- Source
Table - A lowered table-level data source for a
SELECTstatement. - Source
Table Id - An index into a
SourceTable’stablesvector. - Sparse
Record - A record where only a subset of fields are populated.
- Table
Derived - A derived table (inline subquery) used as a table reference.
- Table
With Joins - A
FROMitem: a table reference paired with zero or more joins. - Type
Union - A set of types representing the possible result types of a match expression.
- Typed
Input - An
Inputwrapper that validates resolved argument types against expected types at resolution time. - Update
- An
UPDATEstatement that modifies existing records. - Value
Record - An ordered sequence of
Values representing a record (row). - Value
Stream - An async stream of
Values with optional type checking. - Values
- A
VALUESclause: a set of row expressions. - With
- A
WITHclause containing one or more common table expressions (CTEs).
Enums§
- Assignment
- A field assignment within an
Updatestatement. - Binary
Op - A binary comparison operator.
- Direction
- Sort direction for an
OrderByExpr. - Entry
- A borrowed reference to either an
Expror aValuewithin a composite structure. - Entry
Mut - A mutable reference to either an
Expror aValuewithin a composite structure. - Expr
- An expression node in Toasty’s query AST.
- Expr
Func - A function call expression.
- Expr
Reference - A reference to a model, field, or column.
- ExprSet
- A set of rows produced by a query, set operation, or explicit values.
- Expr
Target - What an expression in the current scope references.
- Insert
Target - The target of an
Insertstatement. - JoinOp
- The type of join and its ON condition.
- Limit
- A
LIMITclause restricting the number of rows returned by a query. - Lock
- A row-level lock to acquire when executing a query.
- Path
Root - The root of a path traversal.
- Resolved
Ref - Result of resolving an
ExprReferenceto its concrete schema location. - Returning
- Specifies what data a statement returns.
- SetOp
- A SQL set operation that combines result sets from multiple queries.
- Source
- The data source for a
Selectstatement’sFROMclause. - Statement
- A top-level statement in Toasty’s AST.
- Table
Factor - A table reference within a
TableWithJoinsrelation. - Table
Ref - A reference to a table within a
SourceTable. - Type
- Statement-level type system for values and expressions within Toasty’s query engine.
- Update
Target - The target of an
Updatestatement. - Value
- A dynamically typed value used throughout Toasty’s query engine.
Traits§
- Entry
Path - A path that can be used to navigate into a composite
ValueorExpr. - Input
- Provides runtime argument and reference resolution for expression evaluation and substitution.
- Into
Expr Target - Conversion trait for producing an
ExprTargetfrom a statement or schema element. - Node
- A node in the statement AST that can be traversed by a visitor.
- Project
- Trait for types that can be projected through a
Projection. - Resolve
- Schema resolution trait used by
ExprContextto look up models, tables, and the model-to-table mapping.