Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ we currently supports the following SQL drives:
- [x] mysql
- [x] mysql2
- [x] sqlite3
- [ ] oracledb
- [x] oracledb
- [x] mssql

## Installation
Expand Down
32 changes: 26 additions & 6 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type * as mysql from 'mysql';
import type * as mysql2 from 'mysql2/promise';
import type * as sqlite3 from 'sqlite3';
import type * as mssql from 'mssql';
// import type * as oracledb from 'oracledb';
import type * as oracledb from 'oracledb';

import { Helper } from 'casbin';
import * as Knex from 'knex';
Expand All @@ -33,6 +33,7 @@ export type Instance = {
mysql2: Promise<mysql2.Connection>;
sqlite3: sqlite3.Database;
mssql: mssql.ConnectionPool;
oracledb: Promise<oracledb.Connection>;
};

const CasbinRuleTable = 'casbin_rule';
Expand Down Expand Up @@ -103,13 +104,13 @@ export class BasicAdapter<T extends keyof Instance> implements Adapter {
return true;
}

async addPolicy(sec: string, ptype: string, rule: string[]): Promise<void> {
async addPolicy(_sec: string, ptype: string, rule: string[]): Promise<void> {
const line = this.savePolicyLine(ptype, rule);
await this.query(this.knex.insert(line).into(CasbinRuleTable).toQuery());
}

async addPolicies(
sec: string,
_sec: string,
ptype: string,
rules: string[][]
): Promise<void> {
Expand All @@ -126,7 +127,7 @@ export class BasicAdapter<T extends keyof Instance> implements Adapter {
}

async removePolicy(
sec: string,
_sec: string,
ptype: string,
rule: string[]
): Promise<void> {
Expand All @@ -137,7 +138,7 @@ export class BasicAdapter<T extends keyof Instance> implements Adapter {
}

async removePolicies(
sec: string,
_sec: string,
ptype: string,
rules: string[][]
): Promise<void> {
Expand All @@ -154,7 +155,7 @@ export class BasicAdapter<T extends keyof Instance> implements Adapter {
}

async removeFilteredPolicy(
sec: string,
_sec: string,
ptype: string,
fieldIndex: number,
...fieldValues: string[]
Expand Down Expand Up @@ -215,6 +216,11 @@ export class BasicAdapter<T extends keyof Instance> implements Adapter {
case 'mssql': {
await (<BasicAdapter<'mssql'>>this).client.close();

break;
}
case 'oracledb': {
await (await (<BasicAdapter<'oracledb'>>this).client).close();

break;
}
}
Expand Down Expand Up @@ -302,6 +308,11 @@ export class BasicAdapter<T extends keyof Instance> implements Adapter {
case 'mssql': {
await (<BasicAdapter<'mssql'>>this).client.connect();

break;
}
case 'oracledb': {
await (<BasicAdapter<'oracledb'>>this).client;

break;
}
}
Expand Down Expand Up @@ -352,6 +363,15 @@ export class BasicAdapter<T extends keyof Instance> implements Adapter {
result = ((await (<BasicAdapter<'mssql'>>this).client.query(sql))
.recordset as unknown) as CasbinRule[] | undefined;

break;
}
case 'oracledb': {
result = (
await (await (<BasicAdapter<'oracledb'>>this).client).execute<
CasbinRule
>(sql)
).rows;

break;
}
}
Expand Down