PostgreSQL native adapter for Node-Casbin. With this library, Node-Casbin can load policy from PosgreSQL database or save policy to it. It supports loading filtered policies and is built for improving performances in PostgreSQL. It uses node-postgres to connect to PostgreSQL.
casbin-pg-adapter also adds advanced filtering capability. You can filter using LIKE or regexp expressions when using loadFilteredPolicy.
Installation
npm install casbin-pg-adapter
Simple example
import{newEnforcer}from"casbin";
importPostgresAdapterfrom"casbin-pg-adapter";
asyncfunctionmyFunction(){
// Initialize a Postgres 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.
If you want to use the savePolicy feature from node-casbin, you have to disable the filtered behavior of PostgresAdapter.
You can do it by calling enableFiltered on the adapter: