Diesel is a Rust library for talking to relational databases with compile-time checks. It supports PostgreSQL, MySQL, SQLite, and MariaDB.
Overview
Diesel is an object-relational mapper and query builder for Rust applications. It aims to cut boilerplate around database access and catch incorrect queries at compile time rather than at runtime, while keeping overhead low through Rust’s type system.
You configure which database backend to use in your project metadata. Supported servers include PostgreSQL, MySQL, SQLite, and MariaDB. Simple loads and filters map cleanly to SQL, and the query builder can express joins and nested conditions when applications need more complex reads.
Codegen generates mapping glue so structs can represent rows for queries, inserts, and updates. Inserts can use dedicated “new record” structs; updates may modify a loaded struct, run batch filters, or apply form-like structs. When the query builder is not enough, Diesel exposes APIs for executing raw SQL while still integrating with its result types.
The project also documents multidatabase abstractions so one codebase can switch between SQLite and Postgres connections where that pattern fits.
Key features
- Compile-time query checking
- PostgreSQL, MySQL, SQLite, MariaDB
- Codegen for row mapping
- Composable query builder
- Insert and update helpers
- Raw SQL escape hatch
Use cases
- Rust web backend data access
- Type-safe SQL in applications
- Multi-database Rust services
- Replacing manual SQL mapping