Available on crate features
model-mysql or model-postgres or model-sqlite only.Expand description
§Model — Async Database Access Layer
An async JPA/Hibernate-style ORM backed by sqlx. Provides:
#[derive(Model)]proc-macro for struct-to-table mappingRepository<T, i64>trait for zero-boilerplate async CRUDQueryBuilder<T>for fluent async filteringDbPoolfor connection management (wrapssqlx::Pool)- Async migration runner
- Relationship helpers (
HasMany,HasOne,BelongsTo)
Enable one or more backend features — model-sqlite, model-postgres,
and model-mysql are not mutually exclusive, so a single binary can hold
pools to more than one backend at once (see Backend):
# SQLite
rust-web-server = { features = ["model-sqlite"] }
# PostgreSQL
rust-web-server = { features = ["model-postgres"] }
# MySQL
rust-web-server = { features = ["model-mysql"] }
# Or more than one at once
rust-web-server = { features = ["model-sqlite", "model-postgres"] }Re-exports§
pub use backend::Backend;pub use connection::DbConfig;pub use connection::DbSslMode;pub use connection::DbTls;pub use migration::MigrationStatus;pub use pool::DbPool;pub use pool::DbTransaction;pub use query::Order;pub use query::QueryBuilder;pub use relation::BelongsTo;pub use relation::HasMany;pub use relation::HasOne;pub use repository::ModelRepository;pub use repository::Repository;pub use crate::pagination::CursorPage;pub use crate::pagination::Page;
Modules§
- backend
Backend— which compiled-in database driver asuper::DbPooluses.- connection
- Database connection configuration.
- migration
- Async migration runner.
- pool
- Async connection pool —
DbPoolandDbTransaction. - query
- Async fluent
QueryBuilder<T>for constructing SQL queries. - relation
- Async relationship helpers:
HasMany,HasOne,BelongsTo. - repository
- Async
Repositorytrait andModelRepositoryimplementation.
Structs§
- DbError
- Error type returned by all model/DB operations.
- Model
Info - What a
Modeltype maps to, read from its trait implementation: the type, its table, its columns and primary key (18.28.0). Rust can’t list the#[derive(Model)]types of a program at run time, so whatever reports models (the dev MCP server’smodelstool,DevTools::model::<T>()) is given each type once. - Model
Row - Backend-independent database row.
Enums§
- Value
- Backend-independent SQL value representation.
Traits§
- From
Column - Convert a
Valueinto a Rust type. - Model
- Trait generated by
#[derive(Model)]. Maps a Rust struct to a database table. - ToColumn
- Convert a Rust value into a
Value.