A database adapter for Node-Casbin supporting PostgreSQL, MySQL, SQLite3, and MSSQL (Oracle listed but experimental). Current version 1.3.0, released sporadically. Key differentiator: provides a unified interface for Casbin policy persistence across multiple SQL databases, with automatic table creation and optional custom table naming. Unlike other Casbin adapters (e.g., sequelize, mongoose), this operates on raw SQL and requires database-specific client libraries as peer dependencies. Ships TypeScript types.
npm install casbin-basic-adapterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows setting up a BasicAdapter with PostgreSQL client, creating an enforcer, and performing an access check.
Instantiate a single client (e.g., new pg.Client(...)) and pass it to newAdapter. Do not use Pool.
Ensure the database exists before using the adapter. The adapter will create the table if it does not exist.
Use PostgreSQL or MySQL instead of Oracle for production.
Pass the desired table name as the third parameter: BasicAdapter.newAdapter('pg', client, 'custom_table')Use import { BasicAdapter } from 'casbin-basic-adapter'Install the required database client: npm install pg
Ensure the database is created and the adapter has permissions to create tables. Alternatively, manually create the table using the adapter's schema.