@prisma/client#CasbinRule TypeScript Examples
The following examples show how to use
@prisma/client#CasbinRule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: adapter.ts From prisma-adapter with Apache License 2.0 | 6 votes |
async savePolicy(model: Model): Promise<boolean> {
await this.#prisma.$executeRaw`DELETE FROM casbin_rule;`;
let astMap = model.model.get('p')!;
const processes: Array<Promise<CasbinRule>> = [];
for (const [ptype, ast] of astMap) {
for (const rule of ast.policy) {
const line = this.#savePolicyLine(ptype, rule);
const p = this.#prisma.casbinRule.create({
data: line,
});
processes.push(p);
}
}
astMap = model.model.get('g')!;
for (const [ptype, ast] of astMap) {
for (const rule of ast.policy) {
const line = this.#savePolicyLine(ptype, rule);
const p = this.#prisma.casbinRule.create({
data: line,
});
processes.push(p);
}
}
// https://github.com/prisma/prisma-client-js/issues/332
await Promise.all(processes);
return true;
}
Example #2
Source File: adapter.ts From prisma-adapter with Apache License 2.0 | 6 votes |
async addPolicies(
sec: string,
ptype: string,
rules: string[][]
): Promise<void> {
const processes: Array<Promise<CasbinRule>> = [];
for (const rule of rules) {
const line = this.#savePolicyLine(ptype, rule);
const p = this.#prisma.casbinRule.create({ data: line });
processes.push(p);
}
// https://github.com/prisma/prisma-client-js/issues/332
await Promise.all(processes);
}