Diesel
Diesel is a mostly-sync ORM and query builder. A compiled schema module plus a Rust DSL produce SQL, and the compiler checks that columns and types match.
Detailed Explanation
Diesel's schema.rs (usually generated by diesel print-schema or the CLI) is a Rust module that names tables and columns. users::table.filter(users::id.eq(id)) is a typed query. A typo in users::nam does not compile. That is the value. You think in Rust method chains; Diesel emits SQL.
The common runtime is blocking. diesel-async exists if you must sit on Tokio, and many teams still run Diesel on spawn_blocking or in a sync service. Do not call blocking Diesel on an Axum worker thread. The ORM is older than the async wave; the compile-time story is why people stay.
Migrations are first-class (diesel migration). Models are structs with Queryable, Insertable, AsChangeset. You do not get a full identity map. Relations are join queries you write, not magic attribute navigation like ActiveRecord. That keeps SQL visible and the N+1 problem obvious.
Compile times grow with the DSL. A huge query file is a huge monomorphisation. Split queries. The schema crate is a compile-time dependency on your database shape; a column you dropped in SQL but not in schema.rs is a compile error, which is what you want after a migration.
When you reach for Diesel: a sync app, or a team that wants the DSL and schema codegen. When you reach for SQLx: async and raw SQL. When you reach for SeaORM: async entities with a gentler learning curve than Diesel's DSL.
Diesel's OptionalExtension and first versus get_result differ on empty results. Learn which call returns NotFound and which returns Ok(None) before you map every error to 500. A missing row is often a 404. A broken connection is a 503. The DSL will not make that distinction for you.
Code Examples
struct User {
id: i32,
name: String,
}
fn filter_by_id(id: i32, users: &[User]) -> Option<&User> {
users.iter().find(|u| u.id == id)
}
fn main() {
let users = [User { id: 17, name: "ada".into() }];
println!("{}", filter_by_id(17, &users).unwrap().name); // prints: ada
}Common Gotchas
Blocking Diesel on a Tokio worker stalls the runtime
Use `diesel-async` or `spawn_blocking`. This is the first production bug in mixed stacks.
Stale `schema.rs` is a compile error or a runtime surprise
Run the CLI after migrations. Do not edit the generated file by hand unless you know why.
The DSL is not SQL
Complex window functions and vendor hints may need `sql_query` and a weakening of the type check.
No implicit lazy relations
A join you forgot is missing data, not a hidden second query — unless you wrote that second query.