What crate should I use for PostgreSQL in 2017?

I have used PostgreSQL for 16 years. I would like to start writing some Rust programs that query the database. I need to connect to PostgreSQL 9.3 and 9.6.

Which crate should I use? I see at least rust-postgres, Diesel, and tokio-postgres.

If you want an ORM - use diesel. If you are ok with writing your sql, use rust-postgres.
Tokio-postgres is async version of rust-postgres (its in the same repo). If you don't know what async or tokio is, you don't want it.

1 Like

Great, that helps. I know what async is and I definitely am not interested. So no Tokio-postgres for me.

I am definitely fine with writing my own SQL. I really just want to use the most stable, useful crate I can find. Perhaps I should try both diesel and rust-postgres and see how I like them.

Diesel and rust-postgres should both be stable and high quality (disclaimer: I wrote rust-postgres :slight_smile:) so it comes down to which feature set you want. Diesel covers the ORM/query builder workflow, where rust-postgres doesn't do that, but gives you direct access to ~all of Postgres's features that you may not get with Diesel (copy queries, notifications, etc).

1 Like

Thanks for letting me know! I think I'll try rust-postgres first. I prefer avoiding middle layers when I can.

1 Like

Note: that in rust it is not always true that more middle layers => worse performance. For example: https://www.reddit.com/r/rust/comments/5hmya5/diesel_is_30_faster_than_rustpostgres_in/ Of cores thare may be lots of other resans to avoid middle layers, just menchaning.


Also a good point. I will make sure to try them both!