Class: TenantRepository<DB, T>
Defined in: packages/persistence/src/scoped.ts:152
The repository base for tenant data. EVERY method takes a Scope (or a
TenantTransaction opened for one) as its first argument, so a call without
a scope does not compile, and a PlatformScope does
not compile either.
Reads are limited to the scope's subtree by the query AND by the transaction's
oktoid.scope_path; a write outside the subtree is refused before it is sent.
A read of a row that is absent and a read of a row out of scope are the same
answer (undefined), so existence does not leak across subtrees.
Extend it for a module's repository; custom queries go through withScope
(the protected scoped), never around it.
Type Parameters
DB
DB
T
T extends keyof DB & string
Constructors
Constructor
new TenantRepository<
DB,T>(db,options):TenantRepository<DB,T>
Defined in: packages/persistence/src/scoped.ts:160
Parameters
db
Database<DB>
The module's pool.
options
The table and its id and path columns.
Returns
TenantRepository<DB, T>
Methods
find()
find(
on,filter?,limit?):Promise<Selectable<DB[T]>[]>
Defined in: packages/persistence/src/scoped.ts:196
Parameters
on
Scope, or the open transaction.
filter?
Partial<Selectable<DB[T]>> = {}
Column equalities; null matches NULL. Empty means all in scope.
limit?
number
At most this many rows, capped at 1000. Default 100.
Returns
Promise<Selectable<DB[T]>[]>
The rows in the subtree matching the filter, by id.
findById()
findById(
on,id):Promise<Selectable<DB[T]> |undefined>
Defined in: packages/persistence/src/scoped.ts:219
Parameters
on
Scope, or the open transaction.
id
unknown
The row id.
Returns
Promise<Selectable<DB[T]> | undefined>
The row, or undefined when absent or out of scope (the same answer).
insert()
insert(
on,row):Promise<Selectable<DB[T]>>
Defined in: packages/persistence/src/scoped.ts:241
Parameters
on
Scope, or the open transaction.
row
Insertable<DB[T]>
The row; its path column must lie within the scope's subtree.
Returns
Promise<Selectable<DB[T]>>
The inserted row.
Throws
outside_scope when the row's path is not within the scope.
scoped()
protectedscoped<R>(on,work):Promise<R>
Defined in: packages/persistence/src/scoped.ts:176
Runs custom work under a scope: the way a subclass obtains a query builder.
Type Parameters
R
R
Parameters
on
A scope, or the transaction to join.
work
(tx) => Promise<R>
Receives the scoped transaction.
Returns
Promise<R>
What work returned.
update()
update(
on,id,patch):Promise<Selectable<DB[T]> |undefined>
Defined in: packages/persistence/src/scoped.ts:265
Parameters
on
Scope, or the open transaction.
id
unknown
The row id.
patch
Updateable<DB[T]>
Columns to change; never the id or the path.
Returns
Promise<Selectable<DB[T]> | undefined>
The updated row, or undefined when absent or out of scope.
Throws
immutable_column when the patch names the id or path.