rustauth-diesel
Diesel database adapters for RustAuth.
This crate provides async-only Diesel integrations for Postgres and MySQL. It
builds on diesel-async deadpool pooling and
RustAuth's shared SQL runner in rustauth-core. The public crate name is
rustauth-diesel; configure CLI migrations with database.adapter = "diesel".
SQLite is not supported. Use rustauth-sqlx for SQLite
(local dev, tests, or small deployments). Sync Diesel is not exposed either.
When to use Diesel vs SQLx
| Your stack | RustAuth adapter |
|---|---|
| App uses Diesel for Postgres or MySQL in production | rustauth-diesel (postgres / mysql) |
| Local dev, tests, or production on SQLite | rustauth-sqlx with sqlite |
| App uses SQLx for Postgres, MySQL, or SQLite | rustauth-sqlx — no need to add Diesel |
| "Diesel everywhere" shop wanting SQLite locally | Use rustauth-sqlx for the auth storage slice, or run Postgres in Docker for parity with prod |
RustAuth intentionally ships one SQLite path: native async SQLx. Diesel SQLite in
diesel-async routes every query through SyncConnectionWrapper (spawn_blocking
over a sync connection), which is a poor fit for concurrent auth CRUD, transactions,
and SQL-backed rate limits. There is no incremental user value over the existing
SQLx adapter (~1900 lines of SQLite tests, CLI migrations, transactional apply).
Install
Postgres:
[]
= { = "0.2", = ["postgres"] }
= { = "1", = ["macros", "rt-multi-thread"] }
MySQL:
[]
= { = "0.2", = ["mysql"] }
= { = "1", = ["macros", "rt-multi-thread"] }
Both backends:
[]
= { = "0.2", = ["postgres", "mysql"] }
= { = "1", = ["macros", "rt-multi-thread"] }
Via the rustauth facade, enable diesel-postgres or
diesel-mysql and import types from rustauth::diesel.
Features
| Feature | Backend | Types |
|---|---|---|
postgres |
PostgreSQL | DieselPostgresAdapter, DieselPostgresStores, DieselPostgresRateLimitStore |
mysql |
MySQL | DieselMysqlAdapter, DieselMysqlStores, DieselMysqlRateLimitStore |
default = [] — enable the backend(s) you need.
Postgres adapter
Adapter id: diesel-postgres.
use DieselPostgresAdapter;
let adapter = connect
.await?;
Bundled adapter + SQL-backed rate-limit store:
use DieselPostgresStores;
let stores = connect
.await?;
let options = stores.apply_to_options;
MySQL adapter
Adapter id: diesel-mysql.
use DieselMysqlAdapter;
let adapter = connect
.await?;
Bundled adapter + SQL-backed rate-limit store:
use DieselMysqlStores;
let stores = connect
.await?;
let options = stores.apply_to_options;
CLI migrations
Configure rustauth.toml with database.adapter = "diesel" and the matching
provider (postgres or mysql):
[]
= "diesel"
= "postgres"
= "DATABASE_URL"
Diesel migration support uses RustAuth's SQL migration planner through this adapter. It does not use Diesel's migration CLI as a second source of schema truth.
Do not configure database.adapter = "diesel-async". The adapter string is
diesel; diesel-async is an internal driver dependency only.
Behavior notes
- Uses
diesel-asyncinternally with deadpool connection pooling (Postgres/MySQL only). - SQLite is not supported — see When to use Diesel vs SQLx.
- Sync Diesel is not exposed; RustAuth's
DbAdaptercontract is async-only. - MySQL array columns are JSON-backed where the shared SQL planner emits array types Postgres handles natively.
Row decoding
Dynamic query results use backend-specific QueryableByName row types
(DieselPostgresRow, DieselMysqlRow)
that capture column values at build time, then decode through the shared
SqlRowReader
boundary.
See NOTES.md for the plan 013 feasibility decision record.
Tests
For route-level parity, test counts, differences, and gaps, see UPSTREAM.md.