HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
diesel-rs
diesel
Rust2016–2025
diesel-rs / diesel

diesel

A safe, extensible ORM and Query Builder for Rust

21Distinct people
25Mentions
0Explicit recommenders
14.2KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

A safe, extensible ORM and Query Builder for Rust

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 8–Nov 15 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/15/2026, 10:01:16 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year25 dated mentions

Observed mentions: 2016-04-19 22:43:29 UTC to 2025-07-28 21:32:01 UTC.

0123452016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 3 mentions; 1 submissions, 2 comments20162017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 5 mentions; 1 submissions, 4 comments2018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 4 mentions; 1 submissions, 3 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 5 mentions; 1 submissions, 4 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 4 mentions; 0 submissions, 4 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2025

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC312
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC514
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC413
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC514
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC202
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC000
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC000
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC101
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC404
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC101

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
A safe, extensible ORM and Query Builder for Rust API Documentation: latest release – main branch Homepage Diesel gets rid of the boilerplate for database interaction and eliminates runtime errors without sacrificing performance. It takes full advantage of Rust's type system to create a low overhead query builder that "feels like Rust." Supported databases: PostgreSQL MySQL SQLite MariaDB You can configure the database backend in Cargo.toml: [dependencies] diesel = { version = "<version>", features = ["<postgres|mysql|sqlite>"] } Getting Started Find our extensive Getting Started tutorial at https://diesel.rs/guides/getting-started. Guides on more specific features are coming soon. Getting help If you run into problems, you can come ask for help at in our GitHub Discussions forum. This is also the right place to propose new features or show your applications. Usage Simple queries Simple queries are a complete breeze. Loading all users from a database: users::table.load(&mut connection) Executed SQL: SELECT * FROM users; Loading all the posts for a user: Post::belonging_to(user).load(&mut connection) Executed SQL: SELECT * FROM posts WHERE user_id = 1; Complex queries Diesel's powerful query builder helps you construct queries as simple or complex as you need, at zero cost. let versions = Version::belonging_to(krate) .select(id) .order(num.desc()) .limit(5); let downloads = version_downloads .filter(date.gt(now - 90.days())) .filter(version_id.eq_any(versions)) .order(date) .load::<Download>(&mut conn)?; Executed SQL: SELECT version_downloads.* FROM version_downloads WHERE date > (NOW() - '90 days') AND version_id = ANY( SELECT id FROM versions WHERE crate_id = 1 ORDER BY num DESC LIMIT 5 ) ORDER BY date Less boilerplate Diesel codegen generates boilerplate for you. It lets you focus on your business logic, not mapping to and from SQL rows. That means you can write this: #[derive(Queryable, Selectable)] #[diesel(table_name = downloads)] pub struct Download { id: i32, version_id: i32, downloads: i32, counted: i32, date: SystemTime, } Instead of this without Diesel: pub struct Download { id: i32, version_id: i32, downloads: i32, counted: i32, date: SystemTime, } impl Download { fn from_row(row: &Row) -> Download { Download { id: row.get("id"), version_id: row.get("version_id"), downloads: row.get("downloads"), counted: row.get("counted"), date: row.get("date"), } } } Inserting data It's not just about reading data. Diesel makes it easy to use structs for new records. #[derive(Insertable)] #[diesel(table_name = users)] struct NewUser<'a> { name: &'a str, hair_color: Option<&'a str>, } let new_users = vec![ NewUser { name: "Sean", hair_color: Some("Black") }, NewUser { name: "Gordon", hair_color: None }, ]; insert_into(users) .values(&new_users) .execute(&mut connection); Executed SQL: INSERT INTO users (name, hair_color) VALUES ('Sean', 'Black'), ('Gordon', DEFAULT) If you need data from the rows you inserted, just change execute to get_result or get_results. Diesel will take care of the rest. let new_users = vec![ NewUser { name: "Sean", hair_color: Some("Black") }, NewUser { name: "Gordon", hair_color: None }, ]; let inserted_users = insert_into(users) .values(&new_users) .get_results::<User>(&mut connection); Executed SQL: INSERT INTO users (name, hair_color) VALUES ('Sean', 'Black'), ('Gordon', DEFAULT) RETURNING * Updating data Diesel's codegen can generate several ways to update a row, letting you encapsulate your logic in the way that makes sense for your app. Modifying a struct: post.published = true; post.save_changes(&mut connection); One-off batch changes: update(users.filter(email.like("%@spammer.com"))) .set(banned.eq(true)) .execute(&mut connection) Using a struct for encapsulation: update(Settings::belonging_to(current_user)) .set(&settings_form) .execute(&mut connection) Raw SQL There will always be certain queries that are just easier to write as raw SQL, or can't be expressed with the query builder. Even in these cases, Diesel provides an easy to use API for writing raw SQL. #[derive(QueryableByName)] #[diesel(table_name = users)] struct User { id: i32, name: String, organization_id: i32, } // Using `include_str!` allows us to keep the SQL in a // separate file, where our editor can give us SQL specific // syntax highlighting. sql_query(include_str!("complex_users_by_organization.sql")) .bind::<Integer, _>(organization_id) .bind::<BigInt, _>(offset) .bind::<BigInt, _>(limit) .load::<User>(&mut conn)?; Code of conduct Anyone who interacts with Diesel in any space, including but not limited to this GitHub repository, must follow our code of conduct. License Licensed under either of these: Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0) MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT) Contributing Before contributing, please read the contributors guide for useful information about setting up Diesel locally, coding style and common abbreviations. Unless you explicitly state otherwise, any contribution you intentionally submit for inclusion in the work, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions. Notable Sponsors and Supporters We would like to thank all of the sponsors supporting the work on Diesel. Notable large sponsors are: NLNet Foundation Prototype Fund GitHub Secure Open Source Fund NGI Zero Core Federal Ministry o
Read the full README on GitHub

What Hacker News says

4 sources
> I thought you hated connection pools? No, you're just being unnecessarily rude. I just said I thought that fine-grained checkin-checkout like Go and Rust encourage is somewhat overrated. There's no need to be hostile. > Postgres specifically supports unnamed prepared statements as a feature, and PgBouncer's model cannot do anything to help those. PqExecParams (single phase prepared statement) works fine over PgBouncer. That's what I'm talking about. This is different to PREPARE & EXEC. You can't actually do a single phase prepared statement from psql, AFAIK, only via client libraries. https://www.postgresql.org/docs/11/libpq-exec.html I agree, the PgBouncer documentation could be clearer. I think they just don't want people trying it to file bug reports. PREPARE and EXEC can actually work even over statement pooling but you need to make
Read the rest
sure your connection setup statements prepare all the necessary statements. > it's a synchronous process, unless you specifically launch that query in its own separate goroutine You're right, I'm getting two things mixed up here. It is a while since I dealt with this problem. 1) The auto-checkout can mean you end up executing related statements on different connections. IMHO this is highly confusing to have as default behaviour and I prefer the Rust approach. 2) By default Go will just keep piling up Goroutines blocked on slow queries and open more DB connections and kill a DB server. Reference for both: http://go-database-sql.org/connection-pool.html > Rust database pools provide an option to limit the upper bound If you're using Rust + Diesel + PG it's actually limited to 10 by default via R2D2: https://github.com/sfackler/r2d2/blob/ad9cdb9f1446c729240cf8... I really think that's a lot saner than "open as many DB connections as you like, what could possibly Go wrong" If you don't believe me that Diesel and single phase prepared statements work with PgBouncer, believe the Diesel maintainer, Sean Griffin: https://github.com/diesel-rs/diesel/issues/1028 I'm back to working in Rust again and plan on opening a PR to resolve this issue.
In Fibers are the right solution to improve Ruby performance
Oh, I should've worded it better. It turns out it's pretty easy to set up Diesel to test your application code together with setting up a lock Postgres database. I had to put it up myself, but overall I just copied the approach Diesel uses for it's own integration test: have a test subproject and set up the database in it's custom compilation script. https://github.com/diesel-rs/diesel/tree/master/diesel_tests Now, every time I alter application code and/or SQL migrations, I immediately test them together automatically.
In Ask HN: What's your favorite way of getting a web app up quickly in 2018?
Any chance you could elaborate on this, because I dont really understand how it answers my original question. I have not checked recently, but last I saw, the database libraries for rust did not use async IO. Looking at (what I presume is) the code for the benchmark [1], it seems it imports the postgres and diesel crates. Last I heard diesel did not support async [2] and looking at the postgres crate [3] it does not mention async, which I assume it would in case it was supported. My whole point was that, sure, I can see how async IO is important for handling many concurrent http requests, but each of those requests would still have to pass through the synchronous database driver which uses threadpooling, right? Or what am I missing here? I can see how it has great performance on the plaintext and json benchamrks, but I dont understand wha
Read the rest
t gives it such a large boost in fortunes or multiple queries. For example, Iron is doing 300k at plaintext/json benchmarks, but drops to 18k on fortunes, and the way I remember the benchmark code it is written in a fairly straight forward way. If the database layer supported 160k requests per second I dont see why we would see such a huge drop? (Edit: 160k is the performance of Actix on fortunes.) I also recall seeing numbers on the 10k order of magnitude from doing naive benchmarks with the various database libraries available, without any http part to the application. But I'm not sure, maybe I'm missing something or remember incorrectly? [1]: https://github.com/TechEmpower/FrameworkBenchmarks/blob/mast... [2]: https://github.com/diesel-rs/diesel/issues/399 [3]: https://crates.io/crates/postgres
In Actix: a small, pragmatic, and fast Rust web framework

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.