For more reasons than we have time to explore in this post, Rust is rapidly gaining popularity in the developer community. One of its selling points is that it supports all major databases and storage formats — from file-based storage platforms, to memory-based and hybrid databases.
In this guide, we’ll compare 11 of the most popular and stable database drivers and ORMs available for Rust. At the end, we’ll compile all the key takeaways in a convenient table to help you choose the right database for your next Rust project.
A database driver is a piece of code that performs communication between the application and the database. It implements protocols and formats for data exchange between application and database.
mysql
MySQL is a very popular database and the first choice for most applications that use the SQL database. The mysql
crate provides a pure Rust implementation of the MySQL protocol. It supports both text-based and binary protocols.
mysql
supports caching of statements as well as pools of connections. TLS is supported via the nativetls
crate. The crate uses the params
for creating rows. One downside is that MySQL does not have async support.
mysql_async
As you might’ve guessed, mysql_async
is an async version of the mysql
driver. It has a lot of APIs that are similar to those found in mysql
, but it may not have some new features since the crates are maintained by different developers.
mysql_async
has full support for MySQL protocol, including TLS-based encryption. mysql_async
crate also allows you to maintain a connection pool. This crate is written in pure Rust.
tokio_postgres
Async Support: Yes
Postgres is a very popular database. Rust has an async implementation for the Postgres protocol that is built on top of tokio async runtime, but it can work with other runtimes as well.
The execution of queries is fully pipelined — i.e., the drivers can send multiple queries. That means tokio-postgres
can process multiple data responses simultaneously. It also supports TLS using nativetls
. The driver doesn’t have a connection pool support since multiple queries can be sent on the same connection.
tokio_postgres
has multiple wrappers for various configs, such as a sync version of the driver, an OpenSSL version, native_tls
version, and many more.
There are also several other crates that feature various additions, including:
postgres-types
postgres-native-tls
postgres-openssl
postgres
redis
Redis is an in-memory database that can be used for creating caches, worker queues, and microservices. Rust has excellent support for the Redis database. The redis
crate provides both high- and low-level APIs. All the queries are pipelined, meaning multiple queries can be sent simultaneously.
redis
has a full implementation of the Redis communication protocol. Support for pub/sub is still in the works. redis
uses tokio as async runtime. This crate supports Lua scripts, auto-reconnect, and connection pool using the r2d2
crate.
rusqlite
Async Support: No
SQLite is an in-process database with SQL support that is used by multiple platforms for maintaining data stores. Android applications often use SQLite as a local database.
Rust has a wrapper around the SQLite C driver. The rusqlite
crate uses bindgen
to create the wrapper, which can result in long compile time. rusqlite
is a safe wrapper around the SQLite wrapper. It also supports hooks such as commit
, insert
, etc.
rusqlite
does not include async support.
leveldb
Created by Google, LeveDB is a key-value store and a key-value store only. It’s not an SQL database; it’s is more like NoSQL.
Many databases use LevelDB as a storage engine. Chrome uses LevelDB to implement IndexDB.
The leveldb
crate provides a safe binding for LevelDB. Like rusqlite
, it may increase compile time since it uses bindgen
. Also like rusqlite
, there is no async support.
mongodb
MongoDB is a NoSQL database. Rust has an official MongoDB driver with async support. It’s written in pure Rust using tokio runtime for async support.
mongodb
has support for aggregation as well as various database operations. It uses the bson
crate to create a BSON document. As of this writing, transactions are not supported.
memcache
Memcached is a free, open-source, high-performance, distributed memory object caching system. memcache
is a Memcached client written in pure Rust. It supports multiple instances of Memcached. Some features, including auto JSON serialization and compression, aren’t available yet.
cdrs
Async Support: No
Cassandra is a distributed, scalable SQL database. crdrs
is a database driver for Cassandra and ScyllaDB.
The crate provides a full implementation of Cassandra protocol and supports clusters. It also supports TLS using nativetls
.
cdrs-async
is an async version of the cdrs
crate based on tokio async runtime.
An object relational mapper (ORM) maps stable rows with Rust structs. ORMs provide support for multiple SQL databases. Many are complete database solutions that include multiple database drivers, connection pool support, and migration tooling. Below are two of the most popular.
diesel
Async Support: No
diesel
is an ORM for Postgres, MySQL, and SQLite. It provides a migration utility called diesel_cli
. diesel
is type-safe, meaning table types are created using migration files. Its goal is to produce identical behavior on multiple databases.
diesel
doesn’t have async support, and the group by query is not well-supported. On stable Rust, the error is a bit weird due to lack of support for procedural macros. It can include long nested types.
Drivers can be changed for a database. The connection pool is supported via r2d2
.
quaint
quaint
is an ORM that supports async operations. It provides AST for creating queries at runtime.
quaint
supports multiple SQL databases, including MySQL, Postgres, and SQLite, as well as the connection pool. It’s not a database type-safe ORM.
The Rust community has built some awesome tools for managing database migrations, a few of which are ORM-independent. The best solution for you will depend on the goals and requirements of your project.
To help you make an informed selection, we’ve compiled the key takeaways, pros, cons, and features associated with each database driver and ORM described above (plus a few more) in a convenient table.
Name | Type | Prod.-ready? | Async support? | Pure Rust? | Pros | Cons | Notes | Maintenance |
mysql |
Driver | Yes | No | Yes |
|
|
|
Active |
mysql_async |
Driver | Yes | Yes | Yes |
|
|
|
Active |
tokio_postgres |
Driver | Yes | Yes | Yes |
|
|
|
Active |
redis |
Driver | Yes | Yes | Yes |
|
|
|
Active |
rusqlite |
Driver | Yes | No | No |
|
|
|
Active |
leveldb |
Driver | Yes | No | No |
|
|
|
Active |
mongodb |
Driver | Yes | Yes | Yes |
|
|
|
Active |
memcache |
Driver | Yes | No | Yes |
|
|
|
Active |
cdrs |
Driver | Yes | No | Yes |
|
|
– Async version available (cdrs-async ) |
Active |
diesel |
ORM | Yes | No | Yes |
|
|
|
Active |
quaint |
ORM | Yes | Yes | Yes |
|
|
Active | |
rustorm |
ORM | No | No | Yes |
|
|
|
Active |
tql |
ORM | No | No | Yes |
|
|
|
Active |
migrant |
Tool | Yes | N/A | Yes |
|
|
Passive | |
refinery |
Tool | Yes | Yes | Yes |
|
Active |
Debugging Rust applications can be difficult, especially when users experience issues that are hard to reproduce. If you’re interested in monitoring and tracking the performance of your Rust apps, automatically surfacing errors, and tracking slow network requests and load time, try LogRocket.
LogRocket is like a DVR for web and mobile apps, recording literally everything that happens on your Rust application. Instead of guessing why problems happen, you can aggregate and report on what state your application was in when an issue occurred. LogRocket also monitors your app’s performance, reporting metrics like client CPU load, client memory usage, and more.
Modernize how you debug your Rust apps — start monitoring for free.
Hey there, want to help make our blog better?
Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.
Sign up nowBuild scalable admin dashboards with Filament and Laravel using Form Builder, Notifications, and Actions for clean, interactive panels.
Break down the parts of a URL and explore APIs for working with them in JavaScript, parsing them, building query strings, checking their validity, etc.
In this guide, explore lazy loading and error loading as two techniques for fetching data in React apps.
Deno is a popular JavaScript runtime, and it recently launched version 2.0 with several new features, bug fixes, and improvements […]
3 Replies to "11 database drivers and ORMs for Rust that are ready for production"
Hello guys! Thanks a lot for the article, pretty nice overview! However I doubt quaint is production ready, as you claim here. At least according to what docs.rs says, it’s not intended to be used in production, yet. Do you have different experience on that? Are you guys using it in production already?
Best regards, Tim
Worth a mention is sqlx (https://github.com/launchbadge/sqlx). (Optional) SQL checked at compile time against a database connection, fully async, DB agnostic. Nice balance between a full ORM and runtime-checked SQL.
Quaint is not an ORM library, and the quaint docs specifically state that it is not their goal to create one.