Request Scope の Client はメソッドをパススルー + RLS
PostgreSQL
NestJS
Client Side
Global Prisma 2
Query Engine
MW
Req Prisma 2
constructor(conf?: RlsConfig) {
this.user.findUnique = this._rebuildQueryMethod(
client.user.findUnique
);
}
private _rebuildQueryMethod(method: Function) {
return (client
.$transaction([
this.$executeRaw(
`SET app.current_tenant='${tenantId}';`
),
Reflect.apply(method, client, args),
this.$executeRaw(
`SET app.current_tenant='';`
),
])
.then((results) => results[1]));
};