Diesel

A safe, extensible ORM and query builder for Rust, supporting PostgreSQL, MySQL, and SQLite.

Library
Cargo
v2.3.13
14,186 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
90 /100 Excellent
Development Activity 96
Maintenance 96
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 87
Code Quality 85
Innovation 84
Learning Curve 65

Diesel is Rust’s most widely used ORM and query builder, designed to eliminate a whole class of runtime database errors by pushing query correctness checks into the compiler. Its query builder generates code such that a query referencing a nonexistent column, mismatched type, or invalid join fails to compile rather than failing at runtime, while still compiling down to efficient, low-overhead SQL.

The project is organized as a Cargo workspace: the core diesel crate provides the query builder, connection handling, and derive-macro-friendly Queryable/Insertable/Selectable traits, while companion crates like diesel_migrations (schema migration embedding and running), diesel_cli (the diesel command-line tool for generating migrations and managing schema), and diesel_derives (the proc-macro implementations) round out the toolchain. Diesel supports PostgreSQL, MySQL, and SQLite as backends, selected via Cargo feature flags.

What You Get

  • A type-safe query builder where invalid columns, joins, or type mismatches fail at compile time instead of at runtime
  • Derive macros (Queryable, Insertable, Selectable, AsChangeset) that eliminate manual row-to-struct mapping boilerplate
  • Support for PostgreSQL, MySQL, and SQLite behind Cargo feature flags, with a consistent query API across backends
  • The companion diesel_migrations crate for embedding and running schema migrations from within the application binary
  • The diesel_cli command-line tool for generating migrations, running diesel migration run, and inferring schema into Rust code
  • Raw SQL escape hatches (sql_query, QueryableByName) for queries too complex to express through the query builder

Common Use Cases

  • Backend web services that want compile-time guarantees their SQL queries match the actual database schema
  • Applications needing to support multiple SQL backends (Postgres/MySQL/SQLite) through one consistent Rust API
  • Projects that want migrations embedded in the compiled binary via diesel_migrations, so schema setup ships with the app itself
  • Teams migrating away from hand-written SQL string queries toward a builder that prevents column/type mistakes before deployment

Under The Hood

Architecture - Diesel is a large Cargo workspace: the core diesel crate (src/query_builder/, src/query_dsl/, src/connection/, per-backend modules under src/pg/, src/mysql/, src/sqlite/) implements the type-level query builder and connection abstraction, diesel_derives supplies the proc-macros that generate Queryable/Insertable impls, diesel_migrations layers embedded migration running on top of the core connection types, and diesel_cli is a separate binary crate that wraps the migration/schema-inference logic for command-line use. Tech Stack - Rust, dual-licensed MIT/Apache-2.0, with backend support gated behind Cargo features (postgres, mysql, sqlite) that pull in the respective native client libraries (libpq, libmysqlclient, libsqlite3); an r2d2.rs module integrates with the r2d2 connection-pooling crate. Code Quality - The core crate’s #[test] blocks are supplemented by a dedicated diesel_tests integration-test crate and a diesel_compile_tests crate that specifically asserts certain invalid queries fail to compile, which is unusual and directly validates the project’s central compile-time-safety claim; 7,745 total commits and 77 tagged releases show a long, actively maintained history. API Design - The learning curve is real (the query DSL’s type-level tricks take time to internalize) but the payoff is substantial: #[derive(Queryable, Selectable)] structs plus users::table.load(&mut conn)-style calls read almost like plain Rust while the compiler statically verifies every column reference and join against the actual schema, and the project’s official “Getting Started” guide plus extensive docs.rs coverage soften the initial ramp-up.

Used by 5 apps in this directory

Dart
74%
AGPL 3.0

AppFlowy

AI Assistants · Collaboration · Productivity

76,967

The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.

View details
66
Repo Health
81
Technical
67
Dependency
Built with
Dart 74%
Rust 24%
Updated 2 weeks ago
Rust
71%
MIT

Trieve

AI Development · Developer Tools · Search

2,719

All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.

View details
42
Repo Health
74
Technical
64
Dependency
Built with
Rust 71%
Updated 8 months ago
Rust
71%
MIT

Trieve

AI Development · Developer Tools · Search

2,719

All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.

View details
42
Repo Health
74
Technical
64
Dependency
Built with
Rust 71%
Updated 8 months ago
Rust
83%
AGPL 3.0

Vaultwarden

Password Manager · Security

68,240

Unofficial Bitwarden-compatible server in Rust — run the full Bitwarden ecosystem on a Raspberry Pi using every official client you already have, without the multi-container overhead.

View details
89
Repo Health
69
Technical
70
Dependency
Built with
Rust 83%
Updated 2 weeks ago
Rust
83%
AGPL 3.0

Vaultwarden

Password Manager · Security

68,240

Unofficial Bitwarden-compatible server in Rust — run the full Bitwarden ecosystem on a Raspberry Pi using every official client you already have, without the multi-container overhead.

View details
89
Repo Health
69
Technical
70
Dependency
Built with
Rust 83%
Updated 2 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers