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.
The module also provides the types that represent associations between
models: HasMany, HasOne, and
BelongsTo. These appear as fields on model structs
and are populated through the generated relation accessors.
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.
§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.DbandTransactionboth implement it. The genericexecmethod ondyn Executoraccepts any typedStatement<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.Error/Result— re-exported fromtoasty-core.
§Derive macros
#[derive(Model)]— generates theModelimpl, query builders, create/update builders, relation accessors, and schema registration for a struct.#[derive(Embed)]— generates theEmbedimpl 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:
| Feature | Driver crate |
|---|---|
sqlite | toasty-driver-sqlite |
postgresql | toasty-driver-postgresql |
mysql | toasty-driver-mysql |
dynamodb | toasty-driver-dynamodb |
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, theDrivertrait, andError/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::BelongsTo;pub use schema::HasMany;pub use schema::HasOne;pub use stmt::Statement;
Modules§
- db
- Database handle, connection pool, executor trait, and transaction support.
- schema
- Model, relation, and schema inspection types.
- 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
ModelSetcontaining 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.
Structs§
Traits§
- Update
Target - Trait for types that can serve as the target of an update operation.