Skip to main content

Class: Database<DB>

Defined in: packages/persistence/src/database.ts:91

A pool of connections held by one role. It exposes no query builder: work runs through withScope (tenant) or @oktoid/persistence/platform (bootstrap), each of which opens a transaction with its scope already set.

Type Parameters​

DB​

DB

Properties​

[dbBrand]?​

readonly optional [dbBrand]?: DB

Defined in: packages/persistence/src/database.ts:93

Phantom: carries the module's table types; never set.

Accessors​

role​

Get Signature​

get role(): string

Defined in: packages/persistence/src/database.ts:150

Returns​

string

The login role this pool connects as.

Methods​

close()​

close(): Promise<void>

Defined in: packages/persistence/src/database.ts:175

Closes the pool. Idempotent: a second call does nothing. After it, withScope, withPlatformScope and withSystemTransaction throw PersistenceError (database_closed), and Database.ping answers false.

Returns​

Promise<void>


declaration()​

declaration(): PoolDeclaration

Defined in: packages/persistence/src/database.ts:145

Returns​

PoolDeclaration

This pool's claim on the server, for checkConnectionBudget.


ping()​

ping(): Promise<boolean>

Defined in: packages/persistence/src/database.ts:159

Liveness for the readiness probe.

Returns​

Promise<boolean>

true when a connection can run a statement.


open()​

static open<DB>(config, options?): Database<DB>

Defined in: packages/persistence/src/database.ts:108

Opens a pool. No connection is made until the first query.

Type Parameters​

DB​

DB

Parameters​

config​

DatabaseConfig

The database block of the service's configuration.

options?​

DatabaseOptions = {}

Tuning that is not declared configuration.

Returns​

Database<DB>

The database.

Throws​

pool.max is not a positive integer.