Skip to content
Knex adapter for Casbin
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.gitignore
.prettierrc
LICENSE
README.md
package.json
yarn.lock

README.md

Knex Adapter

Knex Adapter for Node-Casbin. Use this library for policy storage in Casbin.

For full database support list, go to the Knex documentation.

WARNING: This adapter has only been tested manually. It lacks automated tests, which will show up when I'll have time. If you want to use it in production - be careful.

Installation

npm install casbin-knex-adapter --save

or

yarn add casbin-knex-adapter

Example

const casbin = require('casbin');
const KnexAdapter = require('casbin-knex-adapter');

(async function() {
  // Create adapter
  const adapter = await KnexAdapter.newAdapter(knexOptions);
  // or pass a Knex instance
  // const adapter = await KnexAdapter.newAdapter(knexInstance);

  // Create casbin enforcer
  const enforcer = await casbin.newEnforcer('model.conf', adapter);

  // Load policy from DB
  await enforcer.loadPolicy();

  // Check permission
  if (enforcer.eforce('user', 'resource', 'read')) {
    // Do something
  }

  // Modify policy
  // await enforcer.addPolicy(...)
  // await enforcer.removePolicy(...)

  // Save policy to DB
  await enforcer.savePolicy();
})();
You can’t perform that action at this time.