Awesome Open Source
Awesome Open Source

diesel-adapter Docs CI codecov

Diesel Adapter is the Diesel adapter for Casbin-rs. With this library, Casbin can load policy from Diesel supported database or save policy to it.

Based on Diesel, The current supported databases are:


In order to unify the database table name in Casbin ecosystem, we decide to use casbin_rule instead of casbin_rules from version 0.9.0. If you are using old version diesel-adapter in your production environment, please use following command and update diesel-adapter version:

# MySQL & PostgreSQL & SQLite
ALTER TABLE casbin_rules RENAME TO casbin_rule;


Add it to Cargo.toml

diesel-adapter = { version = "0.9.0", features = ["postgres"] }
tokio = { version = "1.1.1", features = ["macros", "rt-multi-thread"] }

Warning: tokio v1.0 or later is supported from diesel-adapter v0.9.0, we recommend that you upgrade the relevant components to ensure that they work properly. The last version that supports tokio v0.2 is diesel-adapter v0.8.3 , you can choose according to your needs.


Configure env

Rename sample.env to .env and put DATABASE_URL, POOL_SIZE inside

DATABASE_URL=postgres://casbin_rs:[email protected]:5432/casbin
# DATABASE_URL=mysql://casbin_rs:[email protected]:3306/casbin
# DATABASE_URL=casbin.db

Or you can export DATABASE_URL, POOL_SIZE

export DATABASE_URL=postgres://casbin_rs:[email protected]:5432/casbin
export POOL_SIZE=8


use diesel_adapter::casbin::prelude::*;
use diesel_adapter::DieselAdapter;

async fn main() -> Result<()> {
    let mut m = DefaultModel::from_file("examples/rbac_model.conf").await?;
    let a = DieselAdapter::new("postgres://casbin_rs:[email protected]:5432/casbin", 8)?;
    let mut e = Enforcer::new(m, a).await?;


  • postgres
  • mysql
  • sqlite

Attention: postgres, mysql, sqlite are mutual exclusive which means that you can only activate one of them.

Alternatives To Diesel Adapter
Select To Compare

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Rust (61,674
R (59,620
Mysql (31,519
Authentication (26,922
Postgresql (23,950
Permission (11,570
Adapter (11,180
Sqlite (10,049
Orm (5,934
Authorization (5,887
Acl (2,442
Rbac (1,382
Access Control (1,111
Diesel (361
Casbin (298
Abac (189
Storage Driver (102
Casbin Adapter (13
Casbin Rs (7