20 unstable releases (8 breaking)

0.9.0 Jan 31, 2021
0.8.3 Dec 25, 2020
0.8.1 Sep 27, 2020
0.7.3 Jul 31, 2020
0.3.1 Mar 27, 2020
Download history 35/week @ 2021-09-29 33/week @ 2021-10-06 47/week @ 2021-10-13 7/week @ 2021-10-20 6/week @ 2021-10-27 25/week @ 2021-11-03 16/week @ 2021-11-10 17/week @ 2021-11-17 5/week @ 2021-11-24 58/week @ 2021-12-01 124/week @ 2021-12-08 90/week @ 2021-12-15 53/week @ 2021-12-22 12/week @ 2021-12-29 70/week @ 2022-01-05 42/week @ 2022-01-12

192 downloads per month

Apache-2.0

37KB
957 lines

diesel-adapter

Crates.io 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:

Notice

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;

Install

Add it to Cargo.toml

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

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.

Example

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

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

Features

  • postgres
  • mysql
  • sqlite

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

Dependencies

~6–13MB
~268K SLoC

D`