LuaSQL adapter for Lua-Casbin

Clone this repo:

Branches

  1. 1f47131 docs: replace gitter links with discord (#9) by YunShu · 2 years, 9 months ago master
  2. 629a81e feat: add updateFilteredPolicies (#6) by Edmond-J-A · 4 years, 5 months ago
  3. 4b22422 fix: incorrect filtered policies being removed (#7) by Rushikesh Tote · 4 years, 5 months ago
  4. ea0aa58 feat: add updatePolicies (#5) by Edmond-J-A · 4 years, 6 months ago
  5. 5c128ed Merge pull request #3 from rushitote/master by Yang Luo · 4 years, 7 months ago

luasql-adapter

GitHub Action Coverage Status Discord

casbin-adapter is a LuaSQL based adapter for Casbin that supports policies from SQL-based databases (MySQL, PostgreSQL, SQLite3).

Installation

First, install the corresponding driver of LuaSQL from LuaRocks based on the database you use:

  • For MySQL, install luasql-mysql.
  • For PostgreSQL, install luasql-postgres.
  • For SQLite3, install luasql-sqlite3.

Then install the casbin-adapter from LuaRocks by

sudo luarocks install https://raw.githubusercontent.com/casbin-lua/luasql-adapter/master/casbin-adapter-1.0.0-1.rockspec

Usage

To create a new Casbin Enforcer using a MySQL adapter, use:

local Enforcer = require("casbin")
local Adapter = require("casbin.mysql")

local a = Adapter:new(database, user, password, hostname, port) -- hostname, port are optional
local e = Enforcer:new("/path/to/model.conf", a) -- creates a new Casbin enforcer with the model.conf file and the database

For other adapters, replace local Adapter = require("casbin.mysql") with:

  • local Adapter = require("casbin.postgres") for PostgreSQL adapter.
  • local Adapter = require("casbin.sqlite3") for SQLite3 adapter. In SQLite3 adapter, only database field is required and others are optional.

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.