Awesome Open Source
Awesome Open Source

Sequelize Adapter Build Status Coverage Status Godoc

Sequelize Adapter is the Sequelize adapter for Casbin. With this library, Casbin can load policy from Sequelize supported database or save policy to it.

Based on Officially Supported Databases, The current supported databases are:

  • MySQL
  • PostgreSQL
  • Sqlite3
  • Mssql

You may find other 3rd-party supported DBs in Sequelize website or other places.


npm install sequelize-adapter

Simple Example

const Adapter = require('sequelize-adapter')
const { Enforcer } = require('casbin')

module.exports = () => {
	// Initialize a Sequelize adapter and use it in a Casbin enforcer:
	// The adapter will use the MySQL database named "casbin".
	// If it doesn't exist, the adapter will create it automatically.
	const adapter = new Adapter('database', 'username', 'password', {host: 'localhost', dialect: 'mysql', port: 3306}) // Your driver and data source. 
	await adapter.init() // init your db connection and table
	const enforcer = await Enforcer.newEnforcer('rbac_model.conf', adapter)
	// Or you can use an existing DB "abc" like this:
	// The adapter will use the table named "casbin_rule".
	// If it doesn't exist, the adapter will create it automatically.
	// adapter = sequelizeadapter.newAdapter("mysql", "mysql_username:[email protected](", true)

	// Load the policy from DB.
	// Check the permission.
	enforcer.enforce('alice', 'data1', 'read')
	// Modify the policy.
	// e.addPolicy(...)
	// e.removePolicy(...)
	// Save the policy back to DB.

Getting Help


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

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,533,979
Orm (2,107
Authorization (1,336
Sequelize (1,220
Adapter (610
Access Control (398
Casbin (193
Storage Driver (25
Node Casbin (8
Related Projects