Skip to main content

Crate toasty

Crate toasty 

Source
Expand description

Toasty is an async ORM for Rust supporting both SQL (SQLite, PostgreSQL, MySQL) and NoSQL (DynamoDB) databases.

This crate is the user-facing API. It contains the database handle, query execution traits, and the types that generated code builds on. For a tutorial-style introduction, see the Toasty guide.

§Modules

§db — database handle and connection pool

The Db type is the entry point for all database interaction. It owns a connection pool and provides Db::builder for configuration. The module also contains Builder and the pool internals.

§schema — model, relation, and schema inspection

The Model trait represents a root model that maps to a database table. It is implemented by #[derive(Model)] — users do not implement it manually. The module also contains Field, which provides schema registration and runtime helpers for field types, and Auto, a wrapper for auto-generated values such as database-assigned IDs.

Relation fields can use Deferred for lazy loading or direct relation values for eager loading. Lazy relations are populated through .include(...) or generated relation accessors. Eager relations are loaded whenever the model is loaded.

The module also re-exports from toasty-core for inspecting the app-level and db-level schema representations at runtime.

§stmt — typed statement and expression types

Contains the typed wrappers around the statement AST: Query, Insert, Update, Delete, and Statement. Also includes expression helpers like Expr, Path, and the in_list function. Generated query builders (e.g. find_by_*, filter_by_*) produce these types.

§sql — raw SQL execution helpers

Contains sql::statement and sql::query for running backend SQL through Db, Connection, or Transaction handles.

§Key traits

  • Model — a root model backed by a database table. Implemented by #[derive(Model)].
  • Embed — an embedded type whose fields are flattened into the parent model’s table. Implemented by #[derive(Embed)].
  • Executor — the dyn-compatible interface for running statements. Db and Transaction both implement it. The generic exec method on dyn Executor accepts any typed Statement<T>.
  • Load — deserializes a model instance from the database value representation.

§Other key types

  • Transaction / TransactionBuilder — transactions with auto-rollback on drop and nested savepoint support.
  • Page — a page of results from a paginated query, with cursor-based navigation.
  • Batch — groups multiple queries into a single round-trip.
  • Capability / SqlPlaceholder — driver metadata, including SQL placeholder syntax for raw SQL.
  • Error / Result — re-exported from toasty-core.

§Derive macros

  • #[derive(Model)] — generates the Model impl, query builders, create/update builders, relation accessors, and schema registration for a struct.
  • #[derive(Embed)] — generates the Embed impl for a type whose fields are stored inline in a parent model’s table.

§Feature flags

Each database driver is behind an optional feature flag:

FeatureDriver crate
sqlitetoasty-driver-sqlite
postgresqltoasty-driver-postgresql
mysqltoasty-driver-mysql
dynamodbtoasty-driver-dynamodb
tursotoasty-driver-turso

Additional feature flags: rust_decimal, bigdecimal, jiff (date/time via the jiff crate), and serde (JSON serialization support).

§Other crates in the workspace

toasty depends on several internal crates that most users do not need to use directly:

  • toasty-core — shared types used across the workspace: the schema representations (app-level and db-level), the statement AST, the Driver trait, and Error / Result.
  • toasty-macros — the proc-macro entry points and the code generation logic they call.
  • toasty-sql — serializes the statement AST to SQL strings. Used by the SQL driver crates.
  • toasty-driver-* — one crate per database backend.

Re-exports§

pub use stmt::Batch;
pub use stmt::batch;
pub use db::Connection;
pub use db::Db;
pub use db::Executor;
pub use db::Transaction;
pub use db::TransactionBuilder;
pub use schema::Deferred;
pub use stmt::Statement;

Modules§

db
Database handle, connection pool, executor trait, and transaction support.
schema
Model, relation, and schema inspection types.
sql
Raw SQL execution helpers. Raw SQL execution helpers for SQL backends.
stmt
Typed statement, expression, and query builder types.

Macros§

create
Expands struct-literal syntax into create builder method chains. Returns one or more create builders — call .exec(&mut db).await? to insert the record(s).
models
Creates a ModelSet containing the specified models.
query
Builds a query using the Toasty query language. The macro expands into the equivalent method-chain calls on the query builder API. It does not execute the query — chain .exec(&mut db).await? on the result to run it.
update
Expands struct-literal syntax into update-builder method chains. Returns the same builder target.update() would return — call .exec(&mut db).await? to execute the update.

Structs§

Capability
Describes what a database driver supports.
Error
The error type used throughout Toasty.
ModelSet
An ordered collection of Model definitions.

Enums§

SqlPlaceholder
SQL bind-parameter placeholder syntax accepted by a driver.

Traits§

UpdateTarget
Trait for types that can serve as the target of an update operation.

Type Aliases§

Result
A Result type alias that uses Toasty’s Error type.

Derive Macros§

Embed
Derive macro that turns a struct or enum into an embedded type stored inline in a parent model’s table.
Model
Derive macro that turns a struct into a Toasty model backed by a database table.