#casbin #rbac #adapter #rbatis #save-load

casbin-rb-adapter

Rbatis adapter for casbin, support database save and load rules

7 releases

0.1.10 Nov 29, 2024
0.1.9 Jun 27, 2024

#477 in Database interfaces

Download history 1/week @ 2024-09-14 23/week @ 2024-09-21 8/week @ 2024-10-12 1/week @ 2024-10-19 7/week @ 2024-11-02 127/week @ 2024-11-23 41/week @ 2024-11-30

170 downloads per month

Apache-2.0

33KB
674 lines

Crates.io Docs Download

Casbin Rbatis adapter

Rbatis adapter for casbin. With this library, Casbin can load policy or save policy from Rbatis supported databases.

Supported databases, see Rbatis

  • MySQL
  • PostgreSQL
  • SQLite
  • MSSQL
  • ...

Casbin online editor

Get started

Add the following to Cargo.toml:

[dependencies]
casbin-rb-adapter = "0.1"
# casbin or use casbin_rb_adapter::casbin
casbin = "2"

# rbatis integration
rbs = "4"
rbatis = "4"

# choose rbatis driver
# rbdc-mysql = "*"
# rbdc-pg = "*"
# rbdc-sqlite= "*"
# rbdc-mssql = "*"

// or use your project Rbatis static instance
let rb = RBatis::new();
rb.init(MysqlDriver {}, url).unwrap();

let adapter = RbatisAdapter::new(&rb).await?;
// need to call db_sync() to create tables in database
// adapter.db_sync().await?;

let mut e = Enforcer::new("examples/rbac_model.conf", adapter).await?;

// e.enforce((sub, obj, act)).await?;

features:

  • tracing logger for Adapter.
  • runtime-tokio runtime for casbin.
  • runtime-async-std runtime for casbin.

Example

examples

How to run examples:

You need to create a .env file in the project root directory, and add the following configuration:

DATABASE_URL=mysql://root:123456@localhost:3306/casbin

update log

  • v0.1.9: add runtime-tokio and runtime-async-std features for casbin, add tracing feature logger for Adapter. default feature runtime-tokio.

Dependencies

~20–34MB
~527K SLoC