Repolode
diesel-rs

diesel-rs/diesel

A safe, extensible ORM and query builder for Rust that checks queries at compile time across PostgreSQL, MySQL, SQLite and MariaDB.

Stars
14,212
Forks
1,252
Open issues
172
Last commit
2 days ago

What is it?

Diesel is an ORM and query builder for Rust that removes the repetitive code needed to map database rows to structs, while aiming to catch errors at compile time rather than at runtime. It uses Rust's type system to build SQL queries that read like ordinary Rust code, covering selects, filters, ordering, joins-style subqueries, inserts and updates.

Models are declared as Rust structs with derive macros such as Queryable, Selectable and Insertable, and Diesel generates the row-mapping logic from them. Developers can also write raw SQL with sql_query and bind typed parameters when the query builder is not enough.

The library supports PostgreSQL, MySQL, SQLite and MariaDB, with the backend selected through Cargo feature flags. A Getting Started tutorial is available on the project's website, and questions are handled through GitHub Discussions.

Key features

  • 01Compile-time checked queries built from Rust types
  • 02Derive macros that generate row mapping for structs
  • 03Query builder for selects, filters, ordering and subqueries
  • 04Insert and update APIs that accept structs, with RETURNING support
  • 05Raw SQL with typed parameter binding

Use cases

  • Building a Rust web backend that talks to PostgreSQL or MySQL
  • Writing type-safe data access layers for a Rust CLI or service
  • Using SQLite in a Rust desktop or embedded application

Quick start

  1. 1

    Add diesel to Cargo.toml with the feature for your database backend

  2. 2

    Follow the Getting Started tutorial on diesel.rs

Things to know

  • Feature guides beyond Getting Started are still described as coming soon.

Topics

FAQ

What is diesel?
A safe, extensible ORM and query builder for Rust that checks queries at compile time across PostgreSQL, MySQL, SQLite and MariaDB. Diesel is an ORM and query builder for Rust that removes the repetitive code needed to map database rows to structs, while aiming to catch errors at compile time rather than at runtime. It uses Rust's type system to build SQL queries that read like ordinary Rust code, covering selects, filters, ordering, joins-style subqueries, inserts and updates.
Is diesel free to use? What license does it have?
diesel is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is diesel still maintained?
Actively maintained. The last commit to diesel was on Oct 20, 2026.
What can I use diesel for?
Building a Rust web backend that talks to PostgreSQL or MySQL Writing type-safe data access layers for a Rust CLI or service Using SQLite in a Rust desktop or embedded application
How do I install diesel?
Add diesel to Cargo.toml with the feature for your database backend Follow the Getting Started tutorial on diesel.rs
Where can I get diesel?
The source code and installation instructions are on GitHub: https://github.com/diesel-rs/diesel

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects