basalt / prisma/src / TenantClientPool
Class: TenantClientPool<TClient>
Defined in: prisma/src/pool.ts:92
Bounded pool of per-tenant clients — the piece that makes database-per-tenant viable: each tenant gets its own client, and idle ones are evicted (least-recently-used first) so connection counts stay bounded.
Only IDLE clients are evicted: a client with an open lease, or handed out by get() less than idleMs ago, is in use, and disconnecting it would break its in-flight queries and let it silently reconnect outside the pool. When the pool is full of in-use clients a new tenant waits for one to become idle, then fails with TenantPoolExhaustedError — the cap is never exceeded, and never enforced by pulling a client from under its user.
Concurrent first use of a tenant shares ONE in-flight creation, so a burst of requests at a cold tenant cannot open (and leak) duplicate clients.
Type Parameters
TClient
TClient
Constructors
Constructor
> new TenantClientPool<TClient>(options): TenantClientPool<TClient>
Defined in: prisma/src/pool.ts:108
Parameters
options
TenantClientPoolOptions<TClient>
Returns
TenantClientPool<TClient>
Accessors
size
Get Signature
> get size(): number
Defined in: prisma/src/pool.ts:303
Open clients held by the pool (never more than max).
Returns
number
Methods
acquire()
> acquire(tenantId): Promise<TenantClientLease<TClient>>
Defined in: prisma/src/pool.ts:130
The tenant's client, leased: it is never evicted until release() is called. Always release (a finally), or prefer use.
Parameters
tenantId
string
Returns
Promise<TenantClientLease<TClient>>
destroyAll()
> destroyAll(): Promise<void>
Defined in: prisma/src/pool.ts:307
Returns
Promise<void>
get()
> get(tenantId): Promise<TClient>
Defined in: prisma/src/pool.ts:122
The tenant's client. It counts as in use for idleMs after this call — for work that may outlast that, hold it with acquire or use instead.
Parameters
tenantId
string
Returns
Promise<TClient>
has()
> has(tenantId): boolean
Defined in: prisma/src/pool.ts:298
Parameters
tenantId
string
Returns
boolean
use()
> use<T>(tenantId, fn): Promise<T>
Defined in: prisma/src/pool.ts:150
Runs fn with the tenant's client leased for exactly its duration.
Type Parameters
T
T
Parameters
tenantId
string
fn
(client) => T | Promise<T>
Returns
Promise<T>