Gathering detailed insights and metrics for typeorm-adapter
Gathering detailed insights and metrics for typeorm-adapter
Gathering detailed insights and metrics for typeorm-adapter
Gathering detailed insights and metrics for typeorm-adapter
@midwayjs/casbin-typeorm-adapter
midway casbin typeorm adapter
@next-auth/typeorm-legacy-adapter
TypeORM (legacy) adapter for next-auth.
@auth/typeorm-adapter
TypeORM adapter for Auth.js.
@tsdi/typeorm-adapter
@tsdi/typeorm-adapter is typeorm adapter orm for boot application, mvc frameworks on server.
npm install typeorm-adapter
Typescript
Module System
Node Version
NPM Version
68.1
Supply Chain
80.8
Quality
77.5
Maintenance
100
Vulnerability
98.9
License
TypeScript (98.05%)
JavaScript (1.95%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
72 Stars
88 Commits
36 Forks
2 Watchers
1 Branches
20 Contributors
Updated on Mar 23, 2025
Latest Version
1.7.0
Package Id
typeorm-adapter@1.7.0
Unpacked Size
44.32 kB
Size
10.41 kB
File Count
15
NPM Version
10.2.4
Node Version
20.11.1
Published on
Mar 27, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
TypeORM Adapter is the TypeORM adapter for Node-Casbin. With this library, Node-Casbin can load policy from TypeORM supported database or save policy to it.
Based on Officially Supported Databases, the current supported databases are:
You may find other 3rd-party supported DBs in TypeORM website or other places.
npm install typeorm-adapter
1import { newEnforcer } from 'casbin'; 2import TypeORMAdapter from 'typeorm-adapter'; 3 4async function myFunction() { 5 // Initialize a TypeORM adapter and use it in a Node-Casbin enforcer: 6 // The adapter can not automatically create database. 7 // But the adapter will automatically create and use the table named "casbin_rule". 8 // I think ORM should not automatically create databases. 9 const a = await TypeORMAdapter.newAdapter({ 10 type: 'mysql', 11 host: 'localhost', 12 port: 3306, 13 username: 'root', 14 password: '', 15 database: 'casbin', 16 }); 17 18 19 const e = await newEnforcer('examples/rbac_model.conf', a); 20 21 // Load the policy from DB. 22 await e.loadPolicy(); 23 24 // Check the permission. 25 await e.enforce('alice', 'data1', 'read'); 26 27 // Modify the policy. 28 // await e.addPolicy(...); 29 // await e.removePolicy(...); 30 31 // Save the policy back to DB. 32 await e.savePolicy(); 33}
1import { newEnforcer } from 'casbin'; 2import TypeORMAdapter from 'typeorm-adapter'; 3 4async function myFunction() { 5 // Initialize a TypeORM adapter and use it in a Node-Casbin enforcer: 6 // The adapter can not automatically create database. 7 // But the adapter will automatically create and use the table named "casbin_rule". 8 // I think ORM should not automatically create databases. 9 const a = await TypeORMAdapter.newAdapter({ 10 type: 'mysql', 11 host: 'localhost', 12 port: 3306, 13 username: 'root', 14 password: '', 15 database: 'casbin', 16 }); 17 18 19 const e = await newEnforcer('examples/rbac_model.conf', a); 20 21 // Load the filtered policy from DB. 22 await e.loadFilteredPolicy({ 23 'ptype': 'p', 24 'v0': 'alice' 25 }); 26 27 // Check the permission. 28 await e.enforce('alice', 'data1', 'read'); 29 30 // Modify the policy. 31 // await e.addPolicy(...); 32 // await e.removePolicy(...); 33 34 // Save the policy back to DB. 35 await e.savePolicy(); 36}
Use a custom entity that matches the CasbinRule or MongoCasbinRule in order to add additional fields or metadata to the entity.
1import { newEnforcer } from 'casbin'; 2import { 3 CreateDateColumn, 4 UpdateDateColumn, 5} from 'typeorm'; 6import TypeORMAdapter from 'typeorm-adapter'; 7 8@Entity('custom_rule') 9class CustomCasbinRule extends CasbinRule { 10 @CreateDateColumn() 11 createdDate: Date; 12 13 @UpdateDateColumn() 14 updatedDate: Date; 15} 16 17async function myFunction() { 18 // Initialize a TypeORM adapter and use it in a Node-Casbin enforcer: 19 // The adapter can not automatically create database. 20 // But the adapter will automatically create and use the table named "casbin_rule". 21 // I think ORM should not automatically create databases. 22 const a = await TypeORMAdapter.newAdapter({ 23 type: 'mysql', 24 host: 'localhost', 25 port: 3306, 26 username: 'root', 27 password: '', 28 database: 'casbin', 29 }, 30 { 31 customCasbinRuleEntity: CustomCasbinRule, 32 }, 33 ); 34 35 const e = await newEnforcer('examples/rbac_model.conf', a); 36 37 // Load the filtered policy from DB. 38 await e.loadFilteredPolicy({ 39 'ptype': 'p', 40 'v0': 'alice' 41 }); 42 43 // Check the permission. 44 await e.enforce('alice', 'data1', 'read'); 45 46 // Modify the policy. 47 // await e.addPolicy(...); 48 // await e.removePolicy(...); 49 50 // Save the policy back to DB. 51 await e.savePolicy(); 52}
If you want to use a custom table name for the casbin rules, you need to: Create a custom entity class that inherits from CasbinRule and uses the @Entity decorator with your table name. Pass the custom entity class to the entities array of the data source constructor. Pass the custom entity class to the customCasbinRuleEntity option of the typeorm-adapter constructor.
1import { newEnforcer } from 'casbin'; 2import { 3 CreateDateColumn, 4 UpdateDateColumn, 5} from 'typeorm'; 6import TypeORMAdapter from 'typeorm-adapter'; 7 8@Entity('custom_rule') 9class CustomCasbinRule extends CasbinRule { 10 @CreateDateColumn() 11 createdDate: Date; 12 13 @UpdateDateColumn() 14 updatedDate: Date; 15} 16 17async function myFunction() { 18 // Initialize a TypeORM adapter and use it in a Node-Casbin enforcer: 19 // The adapter can not automatically create database. 20 // But the adapter will automatically create and use the table named "casbin_rule". 21 // I think ORM should not automatically create databases. 22 23 const datasource = new DataSource({ 24 type: 'mysql', 25 host: 'localhost', 26 port: 3306, 27 username: 'root', 28 password: '', 29 database: 'casbin', 30 entities: [CustomCasbinRule], 31 synchronize: true, 32 }); 33 34 const a = await TypeORMAdapter.newAdapter( 35 { connection: datasource }, 36 { 37 customCasbinRuleEntity: CustomCasbinRule, 38 }, 39 ); 40 41 const e = await newEnforcer('examples/rbac_model.conf', a); 42 43 // Load the filtered policy from DB. 44 await e.loadFilteredPolicy({ 45 'ptype': 'p', 46 'v0': 'alice' 47 }); 48 49 // Check the permission. 50 await e.enforce('alice', 'data1', 'read'); 51 52 // Modify the policy. 53 // await e.addPolicy(...); 54 // await e.removePolicy(...); 55 56 // Save the policy back to DB. 57 await e.savePolicy(); 58}
This project is under Apache 2.0 License. See the LICENSE file for the full license text.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 13/17 approved changesets -- score normalized to 7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
15 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More