basalt / prisma/src / tenantClient
Function: tenantClient()
> tenantClient<T>(): T
Defined in: prisma/src/index.ts:170
A client that resolves from the context on every access.
The -prisma stores take a client when they are built — at boot — and hold it for the life of the process. Under schema-per-tenant the right client is only known per request, so what they must hold is not a client but a way to reach one:
const tenantDb = tenantClient<PrismaClient>()
const auth = prismaAuthStores(tenantDb)
const perms = prismaAccessStore(tenantDb)Every application doing this wrote the same proxy by hand, because the pattern was tolerated — ensureModel catches the "not yet resolvable" case explicitly — but never supplied. Writing it wrong does not raise an error: it points every tenant at whatever client was passed instead, which in the usual mistake is the central one. Tenant data, silently, in the wrong schema.
Not a substitute for db(): inside a request, call db(). This is for the handful of places that must be constructed before a request exists.
Type Parameters
T
T extends object = Record<string, unknown>
Returns
T