Skip to content

basalt / tenancy-sqlite/src / SqliteTenantSource

Class: SqliteTenantSource ​

Defined in: tenancy-sqlite/src/index.ts:65

Where tenants are loaded from — the app's database in production.

Implements ​

Constructors ​

Constructor ​

> new SqliteTenantSource(db): SqliteTenantSource

Defined in: tenancy-sqlite/src/index.ts:66

Parameters ​

db ​

DatabaseSync

Returns ​

SqliteTenantSource

Properties ​

db ​

> readonly db: DatabaseSync

Defined in: tenancy-sqlite/src/index.ts:66

Methods ​

create() ​

> create(tenant): Promise<Tenant>

Defined in: tenancy-sqlite/src/index.ts:96

Insert a NEW tenant and its custom-domain set, in one transaction; an existing id throws TenantAlreadyExistsError and leaves that tenant untouched.

A plain INSERT, not a lookup followed by a write: the primary key refuses the duplicate, and BEGIN IMMEDIATE serialises writers across processes sharing the file, so of two concurrent creates of the same id exactly one wins. This is what tenancy.create() calls.

Parameters ​

tenant ​

Tenant

Returns ​

Promise<Tenant>

Implementation of ​

TenantSource.create


delete() ​

> delete(id): Promise<void>

Defined in: tenancy-sqlite/src/index.ts:149

Removes a tenant and its domains — the TenantSource.delete the contract asks for, and what tenancy.destroy() calls. Without it, destroy refuses.

Parameters ​

id ​

string

Returns ​

Promise<void>

Implementation of ​

TenantSource.delete


find() ​

> find(id): Promise<Tenant | null>

Defined in: tenancy-sqlite/src/index.ts:128

Parameters ​

id ​

string

Returns ​

Promise<Tenant | null>

Implementation of ​

TenantSource.find


findByDomain() ​

> findByDomain(domain): Promise<Tenant | null>

Defined in: tenancy-sqlite/src/index.ts:133

Required by the domain resolver (custom domains).

Parameters ​

domain ​

string

Returns ​

Promise<Tenant | null>

Implementation of ​

TenantSource.findByDomain


list() ​

> list(): Promise<Tenant[]>

Defined in: tenancy-sqlite/src/index.ts:140

Required by tenancy.forEach() and basalt tenant:list.

Returns ​

Promise<Tenant[]>

Implementation of ​

TenantSource.list


remove() ​

> remove(id): Promise<boolean>

Defined in: tenancy-sqlite/src/index.ts:154

Delete a tenant and its domains. Returns whether a tenant was removed.

Parameters ​

id ​

string

Returns ​

Promise<boolean>


save() ​

> save(tenant): Promise<Tenant>

Defined in: tenancy-sqlite/src/index.ts:78

Insert or update a tenant and replace its custom-domain set in one transaction. Claiming a domain already owned by a different tenant throws (domains are globally unique — routing must be unambiguous); the whole save rolls back so the tenant record and its domains never drift apart.

An upsert replaces the whole record. That is right for an intentional update and for status transitions; it is wrong for creating a tenant, which is what create is for.

Parameters ​

tenant ​

Tenant

Returns ​

Promise<Tenant>

Implementation of ​

TenantSource.save

Released under the MIT License.