Function: withScope()
withScope<
DB,R>(db,scope,work):Promise<R>
Defined in: packages/persistence/src/scoped.ts:84
Opens a transaction for a tenant scope: the ONLY way to obtain a query builder for
tenant data. The first statement sets oktoid.scope_path (and clears
oktoid.platform) with SET LOCAL semantics, so a pooled connection carries
nothing into its next use, and a row-level-security policy can read it.
Type Parameters
DB
DB
R
R
Parameters
db
Database<DB>
The module's pool.
scope
A scope minted by messaging. A forged one is refused.
work
(tx) => Promise<R>
Runs in the transaction; a throw rolls it back.
Returns
Promise<R>
What work returned, after commit, and after the effects registered with
TenantTransaction.afterCommit have run.
Throws
forged_scope when scope was not minted.