Skip to content

basalt / prisma/src / tenantTransaction

Function: tenantTransaction() ​

> tenantTransaction<C, R>(client, fn, options?): Promise<R>

Defined in: prisma/src/extension.ts:653

Opens an interactive transaction with the RLS tenant already set on ITS connection: set_config('app.tenant_id', <tenant>, true) runs first, then fn(tx). Pass the tenant-scoped client ($extends(tenancyExtension(...))) — tx stays tenant-scoped, and every statement in fn is filtered by the RLS policies too.

await tenantTransaction(db, async (tx) => { const invoice = await tx.invoice.create({ data }) await tx.invoiceLine.createMany({ data: lines(invoice.id) }) })

Use tx inside fn: the outer client is not part of the transaction. Throws MissingTenantError with no tenant in scope.

Type Parameters ​

C ​

C

R ​

R

Parameters ​

client ​

C

fn ​

(tx) => Promise&lt;R&gt;

options? ​

TenantTransactionOptions = {}

Returns ​

Promise&lt;R&gt;

Released under the MIT License.