Expand description
SQL AST and query builder for the Turso dialect.
This crate is the SQL layer of turso-orm. It owns the abstract syntax
tree of a statement — identifiers, values, expressions, DML and DDL
builders — and the single writer that renders that tree to SQL text with
? placeholders and the values to bind. It deliberately targets one
dialect, the SQLite grammar as implemented by Turso, which is why it stays
small, has no runtime dependency and binds parameters directly as Turso
storage-class Values rather than through a generic value model.
The crate does not execute anything: it never touches a connection and
knows nothing about rows. Executing a Statement is the job of
turso-orm-driver, and mapping entities onto statements is the job of
turso-orm.
Iden,Ident,TableRef,ColumnRef: identifiers, always rendered double-quoted so reserved words and mixed case are safe;Value: the five SQLite storage classes, withFromconversions for the common Rust types and, behind feature flags,chrono,uuid,serde_jsonandrust_decimal;ExprandCondition: expressions and composableAND/ORgroups that parenthesise themselves so precedence is never ambiguous;QueryandTable: entry points to the DML and DDL builders;BuildandStatement: rendering to SQL plus bound values.
§Example
use turso_sql::prelude::*;
let (sql, values) = Query::select()
.column("id")
.column("name")
.from("user")
.and_where(Expr::col("age").gte(18))
.order_by("name", Order::Asc)
.limit(10)
.build();
assert_eq!(
sql,
r#"SELECT "id", "name" FROM "user" WHERE "age" >= ? ORDER BY "name" ASC LIMIT ?"#
);
assert_eq!(values, vec![Value::Integer(18), Value::Integer(10)]);Modules§
- prelude
- Everything needed to build queries, for a single glob import.
Structs§
- Alter
Table - An
ALTER TABLEstatement. - Column
Def - A column definition.
- Condition
- A composable
WHERE/HAVINGcondition. - Create
Index - A
CREATE INDEXstatement. - Create
Table - A
CREATE TABLEstatement. - Delete
- A
DELETEstatement. - Drop
Index - A
DROP INDEXstatement. - Drop
Table - A
DROP TABLEstatement. - Foreign
Key - A foreign-key constraint.
- Func
- A function call.
- Ident
- An owned identifier.
- Insert
- An
INSERTstatement. - Join
- A join clause.
- OnConflict
- An
ON CONFLICTclause for inserts. - Query
- The entry point to the DML builders, mirroring the
Query::select()style. - Select
- A
SELECTstatement. - Statement
- A rendered statement: SQL with
?placeholders and the values to bind. - Table
- The entry point to the DDL builders.
- Table
Ref - A table reference with an optional alias.
- Update
- An
UPDATEstatement.
Enums§
- Column
Ref - A column reference, optionally qualified by table.
- Column
Type - The logical column types.
- Expr
- A SQL expression.
- Foreign
KeyAction - The referential actions of a foreign key.
- Join
Type - The join kinds.
- Order
- A sort direction.
- Returning
- A
RETURNINGclause. - Select
Item - An item of a select list.
- Table
Constraint - The table-level constraints.
- Value
- A bound parameter or literal.
Constants§
- NAIVE_
DATETIME_ FORMAT with-chrono - The text format used for naive timestamps.