MultiTenantManager
@abimongo/core / MultiTenantManager
Class: MultiTenantManager
Defined in: core/src/tanancy/MultiTenantManager.ts:11
Manages multi-tenancy by handling tenant-specific MongoDB connections. Provides methods for registering tenants, retrieving clients, and supporting lazy connections.
Constructors
Constructor
new MultiTenantManager():
MultiTenantManager
Defined in: core/src/tanancy/MultiTenantManager.ts:15
Returns
MultiTenantManager
Methods
getAllConnectedTenants()
staticgetAllConnectedTenants():string[]
Defined in: core/src/tanancy/MultiTenantManager.ts:86
Returns
string[]
getClient()
staticgetClient(tenantId):Promise<MongoClient|null>
Defined in: core/src/tanancy/MultiTenantManager.ts:67
Retrieves the MongoClient instance for a specific tenant. If the tenant is registered for lazy connection, it establishes the connection before returning the client.
Parameters
tenantId
string
The ID of the tenant to retrieve.
Returns
Promise<MongoClient | null>
A promise that resolves to the MongoClient instance or null if the tenant is not registered.
getConnectedTenant()
staticgetConnectedTenant():string
Defined in: core/src/tanancy/MultiTenantManager.ts:82
Returns
string
hasTenant()
statichasTenant(tenantId):boolean
Defined in: core/src/tanancy/MultiTenantManager.ts:22
Checks if a tenant is already registered.
Parameters
tenantId
string
The ID of the tenant to check.
Returns
boolean
true if the tenant is registered, false otherwise.
registerLazyTenant()
staticregisterLazyTenant(tenantId,uri,logger?):void
Defined in: core/src/tanancy/MultiTenantManager.ts:34
Registers a tenant with the given ID and MongoDB URI for lazy connection. Lazy connections are established only when the tenant is accessed for the first time.
Parameters
tenantId
string
The ID of the tenant to register.
uri
string
The MongoDB URI for the tenant.
logger?
Optional logger for logging messages.
Returns
void
registerTenant()
staticregisterTenant(tenantId,uri):Promise<MongoClient>
Defined in: core/src/tanancy/MultiTenantManager.ts:51
Registers a tenant with the given ID and MongoDB URI. If the tenant is already registered, it returns the existing client.
Parameters
tenantId
string
The ID of the tenant to register.
uri
string
The MongoDB URI for the tenant.
Returns
Promise<MongoClient>
A promise that resolves to the MongoClient instance for the tenant.