Registry / security / drizzle-adapter

drizzle-adapter

JSON →
library1.4.0jsnpmunverified

Drizzle Adapter v1.4.0 is the official Drizzle ORM adapter for Node-Casbin, enabling policy storage and retrieval from databases supported by Drizzle ORM (PostgreSQL, MySQL, SQLite, Turso, Neon, PlanetScale, Vercel Postgres, Xata, and more). It uses the Drizzle ORM query builder to interact with databases, providing type-safe and efficient policy management. The package follows the Casbin adapter interface and supports all core Casbin features (RBAC, ABAC, ACL). It requires casbin ^5.0.0 and drizzle-orm >=0.29.0. Active development, weekly releases, and full TypeScript support.

npm install drizzle-adapter
INSTALL
IMPORT
SIG · DRIZZLE-ADAPTER
D
drizzle-adapter
securityjavascriptv1.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DrizzleAdapter
✓ import DrizzleAdapter from 'drizzle-adapter'
✗ const DrizzleAdapter = require('drizzle-adapter')
ESM-only package; CJS require is not supported. DrizzleAdapter is the default export.
casbinRuleSqlite
✓ import { casbinRuleSqlite } from 'drizzle-adapter'
✗ import casbinRuleSqlite from 'drizzle-adapter/casbinRuleSqlite'
Named export, not a default export. Available table schemas include casbinRuleSqlite, casbinRulePostgres, casbinRuleMysql, etc.
DrizzleAdapter.newAdapter
✓ await DrizzleAdapter.newAdapter({ db, table })
✗ new DrizzleAdapter({ db, table })
DrizzleAdapter cannot be instantiated with 'new'. Use the static async factory method newAdapter().

Initializes a SQLite database, creates the casbin_rule table, creates a DrizzleAdapter, and performs a policy enforcement check.

import { newEnforcer } from 'casbin'; import { drizzle } from 'drizzle-orm/better-sqlite3'; import Database from 'better-sqlite3'; import DrizzleAdapter, { casbinRuleSqlite } from 'drizzle-adapter'; async function main() { const sqlite = new Database('casbin.db'); const db = drizzle(sqlite); db.run(`CREATE TABLE IF NOT EXISTS casbin_rule ( id INTEGER PRIMARY KEY AUTOINCREMENT, ptype TEXT, v0 TEXT, v1 TEXT, v2 TEXT, v3 TEXT, v4 TEXT, v5 TEXT )`); const adapter = await DrizzleAdapter.newAdapter({ db, table: casbinRuleSqlite }); const enforcer = await newEnforcer('examples/rbac_model.conf', adapter); await enforcer.loadPolicy(); console.log(await enforcer.enforce('alice', 'data1', 'read')); }
Debug
Known issues
breakingDrizzleAdapter cannot be instantiated with 'new' - use static factory method DrizzleAdapter.newAdapter()
fix
Use await DrizzleAdapter.newAdapter({ db, table }) instead of new DrizzleAdapter()
affects: >=1.0.0
deprecatedas casbinRule is deprecated in commonjs and removed from named exports; use specific table names (e.g., casbinRuleSqlite)
fix
Import from drizzle-adapter: { casbinRuleSqlite } instead of 'casbinRule'
affects: >=0.0.1
gotchaThe provided 'db' object must be the result of drizzle() call, not a raw driver instance
fix
Use const db = drizzle(poolOrClient) before passing to newAdapter
affects: >=1.0.0
gotchaThe 'table' option is required - missing it will cause a runtime error
fix
Always pass the table schema exported by drizzle-adapter: { casbinRuleSqlite, casbinRulePostgres, casbinRuleMysql }
affects: >=1.0.0
gotchaESM-only package; require() will throw ERR_REQUIRE_ESM
fix
Use import syntax or dynamic import() instead of require()
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: DrizzleAdapter is not a constructor
Using 'new DrizzleAdapter()' instead of the static factory method
fix
Use 'await DrizzleAdapter.newAdapter({ db, table })'
ERR_REQUIRE_ESM
Trying to require('drizzle-adapter') in a CJS context
fix
Use 'import DrizzleAdapter from "drizzle-adapter"' or set type: module in package.json
Cannot find module 'drizzle-orm'
Missing peer dependency drizzle-orm
fix
Run 'npm install drizzle-orm' or install the appropriate database driver
Error: Cannot read properties of undefined (reading 'column')
Passing a raw driver instance instead of drizzle() result
fix
Pass the drizzle() returned object: const db = drizzle(poolOrClient)
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies
casbinrequiredPeer dependency for enforcer and model functionality
drizzle-ormrequiredPeer dependency for database interaction via Drizzle ORM
Agent activity
20 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
drizzle-adapter — npm install drizzle-adapter · libregistry