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:

````SQL

MySQL & PostgreSQL & SQLite

ALTER TABLE casbinrules RENAME TO casbinrule; ````

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

```rust use dieseladapter::casbin::prelude::*; use dieseladapter::DieselAdapter;

[async_std::main]

async fn main() -> Result<()> { let mut m = DefaultModel::fromfile("examples/rbacmodel.conf").await?; let a = DieselAdapter::new("postgres://casbinrs:casbinrs@127.0.0.1:5432/casbin", 8)?; let mut e = Enforcer::new(m, a).await?; Ok(()) } ```

Features

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