diesel-adapter 0.7.2

Diesel adapter for casbin-rs
Documentation

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:

Install

Add it to Cargo.toml

diesel-adapter = { version = "0.7.2", features = ["postgres"] }
async-std = "1.6.2"

Configure

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

DATABASE_URL=postgres://casbin_rs:casbin_rs@127.0.0.1:5432/casbin
# DATABASE_URL=mysql://casbin_rs:casbin_rs@127.0.0.1:3306/casbin
POOL_SIZE=8

Or you can export DATABASE_URL, POOL_SIZE

export DATABASE_URL=postgres://casbin_rs:casbin_rs@127.0.0.1:5432/casbin
export POOL_SIZE=8

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()?;
    let mut e = Enforcer::new(m, a).await?;
    Ok(())
}

Features

  • postgres
  • mysql

Attention: postgres and mysql are mutual exclusive which means that you can only activate one of them. Currently we don't have support for sqlite, it may be added in the near future.