0.7.2 • Published 3 years ago

casbin-knex-adapter v0.7.2

Weekly downloads
151
License
Apache-2.0
Repository
github
Last release
3 years ago

Knex Adapter

NPM Version npm.io Coverage Status

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

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

Installation

npm install casbin-knex-adapter --save

or

yarn add casbin-knex-adapter

Example

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

(async function() {
  // Instantiate DB connection
  const knex = Knex(knexOptions)
  // Create adapter
  const adapter = await KnexAdapter.newAdapter({ knex });

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

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

  // Check permission
  if (await enforcer.enforce('user', 'resource', 'read')) {
    // Do something if user is authorized
  }

  // Modify policy
  // await enforcer.addPolicy(...)
  // await enforcer.removePolicy(...)
  // await adapter.removePolicyWhere({ 'v0': '00001' }) // needs to be reloaded from enforcer afterwards

  // Rewrite entire policy in DB
  await enforcer.savePolicy();
})();
0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago