casbin-orm-adapter is a 4DaysORM based adapter for Casbin that supports policies from MySQL and SQLite3 databases.
First, install the corresponding driver of LuaSQL from LuaRocks based on the database you use:
Then install the casbin-orm-adapter from LuaRocks by:
sudo luarocks install https://raw.githubusercontent.com/casbin-lua/4daysorm-adapter/master/casbin-orm-adapter-1.0.0-1.rockspec
To create a new Casbin Enforcer using the adapter, you need to create a global variable DB containing the database configuration details (more details here):
DB = { type = "mysql", -- or "sqlite3" name = "your_database_name", username = "your_username", password = "your_password", new = true } local Enforcer = require("casbin") local Adapter = require("CasbinAdapter") local a = Adapter:new() -- uses the global DB configuration local e = Enforcer:new("/path/to/model.conf", a) -- creates a new Casbin enforcer with the model.conf file and the database
This project is under Apache 2.0 License. See the LICENSE file for the full license text.