Skip to content
TypeORM adapter for Casbin
Branch: master
Clone or download
Latest commit 9978ba8 Feb 21, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Finish Oct 15, 2018
src Fix #4 Feb 21, 2019
test Finish Oct 15, 2018
.gitignore Finish Oct 15, 2018
.travis.yml Create database in Travis CI, fix the badges. Oct 18, 2018
LICENSE Finish Oct 15, 2018 Create database in Travis CI, fix the badges. Oct 18, 2018
package.json Bump to v1.0.3 Feb 21, 2019
tsconfig.json Finish Oct 15, 2018
tslint.json Finish Oct 15, 2018
yarn.lock Finish Oct 15, 2018

TypeORM Adapter

NPM version NPM download codebeat badge Build Status Coverage Status Gitter

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

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

  • MySQL
  • PostgreSQL
  • MariaDB
  • SQLite
  • MS SQL Server
  • Oracle
  • WebSQL
  • MongoDB

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


npm install typeorm-adapter

Simple Example

import {Enforcer} from 'casbin';
import TypeORMAdapter from 'typeorm-adapter';

async function myFunction() {
    // Initialize a TypeORM adapter and use it in a Node-Casbin enforcer:
    // The adapter can not automatically create database.
    // But the adapter will automatically and use the table named "casbin_rule".
    // I think ORM should not automatically create databases.  
    const a = await TypeORMAdapter.newAdapter({
        type: 'mysql',
        host: 'localhost',
        port: 3306,
        username: 'root',
        password: '',
        database: 'casbin',

    const e = await Enforcer.newEnforcer('examples/rbac_model.conf', a);

    // Load the policy from DB.
    await e.loadPolicy();

    // Check the permission.
    e.enforce('alice', 'data1', 'read');

    // Modify the policy.
    // await e.addPolicy(...);
    // await e.removePolicy(...);

    // Save the policy back to DB.
    await e.savePolicy();

Getting Help


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

You can’t perform that action at this time.