Skip to main content

PostgresRelationalStore

@webda/postgres


Class: PostgresRelationalStore<K>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:109

Store models in typed PostgreSQL tables: one column per field, primary and foreign keys, junction tables for the link collections, indexes, generated from the model metadata by @webda/sql-schema

The models are listed explicitly (models): the store never takes the fallback role of the Registry. The schema is created or extended at init() (schemaSync), never destructively.

Webda Modda​

Extends​

Type Parameters​

K​

K extends PostgresRelationalParameters = PostgresRelationalParameters

Constructors​

Constructor​

new PostgresRelationalStore<K>(name, params): PostgresRelationalStore<K>

Defined in: packages/core/lib/services/service.d.ts:72

Create a new Service instance

Service

Parameters​

name​

string

The name of the service

params​

K

The parameters block define in the configuration file

Returns​

PostgresRelationalStore<K>

Inherited from​

PostgresStore.constructor

Properties​

_compiledCapabilities​

protected _compiledCapabilities: Record<string, any>

Defined in: packages/core/lib/services/iservice.d.ts:50

Capabilities detected at compile-time from @WebdaCapability-tagged interfaces.

Populated during Service.resolve by reading the service's entry in webda.module.json. Each key is a capability name (e.g., "request-filter"), and the value is an empty object {} by default. Override getCapabilities to provide capability-specific configuration or to conditionally disable capabilities.

See​

getCapabilities

Inherited from​

PostgresStore._compiledCapabilities


_migratedBy?​

optional _migratedBy?: Store<StoreParameters, StoreEvents>

Defined in: packages/core/lib/stores/store.d.ts:362

MigrationStore currently wrapping this store as source or target

Inherited from​

PostgresStore._migratedBy


_modelMetadatas​

_modelMetadatas: Map<string, ModelMetadata>

Defined in: packages/core/lib/stores/store.d.ts:356

Metadata for each model in _models, keyed by Identifier.

Inherited from​

PostgresStore._modelMetadatas


_models​

_models: ModelClass<Storable<any, any>>[]

Defined in: packages/core/lib/stores/store.d.ts:354

All model classes managed by this store. Index 0 is the legacy "primary" model.

Inherited from​

PostgresStore._models


_modelsHierarchy​

_modelsHierarchy: object

Defined in: packages/core/lib/stores/store.d.ts:358

Store the manager hierarchy with their depth

Index Signature​

[key: string]: number

Inherited from​

PostgresStore._modelsHierarchy


[WEBDA_EVENTS]​

[WEBDA_EVENTS]: StoreEvents

Defined in: packages/core/lib/services/service.d.ts:50

Set the Webda events here

Inherited from​

PostgresStore.[WEBDA_EVENTS]


client​

client: Client | Pool

Defined in: packages/postgres/src/postgresstore.service.ts:103

Client

Inherited from​

PostgresStore.client


dialect​

protected readonly dialect: SQLDialect

Defined in: packages/sql/lib/store.d.ts:54

Engine syntax, created once per store

Inherited from​

PostgresStore.dialect


explicitParticipant?​

protected optional explicitParticipant?: OperationTransactionParticipant

Defined in: packages/sql/lib/store.d.ts:90

Participant enlisted by withTransaction, whatever the transaction mode

Inherited from​

PostgresStore.explicitParticipant


logger​

protected logger: Logger

Defined in: packages/core/lib/services/service.d.ts:59

Logger with class context

Inherited from​

PostgresStore.logger


metrics​

metrics: object

Defined in: packages/core/lib/stores/store.d.ts:376

Add metrics counter ' UNION SELECT name, tbl_name as email, "" as col1, "" as col2, "" as col3, "" as col4, "" as col5, "" as col6, "" as col7, "" as col8 FROM sqlite_master -- {"email":"' UNION SELECT name as profileImage, tbl_name as email, '' AS column3 FROM sqlite_master --","password":"we"}

operations_total​

operations_total: Counter

queries​

queries: Histogram

slow_queries_total​

slow_queries_total: Counter

Inherited from​

PostgresStore.metrics


name​

readonly name: string

Defined in: packages/core/lib/services/iservice.d.ts:27

Name

Inherited from​

PostgresStore.name


ownsPool​

protected ownsPool: boolean = false

Defined in: packages/postgres/src/postgresstore.service.ts:108

True when client is a shared pool acquired from the registry. Tracked so stop only releases pools it took a refcount on.

Inherited from​

PostgresStore.ownsPool


parameters​

readonly parameters: K

Defined in: packages/core/lib/services/iservice.d.ts:31

Parameters

Inherited from​

PostgresStore.parameters


relational​

protected readonly relational: RelationalStoreSupport

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:115

Relational


tablesReady​

protected tablesReady: Map<string, Promise<void>>

Defined in: packages/sql/lib/store.d.ts:59

Pending or completed CREATE TABLE IF NOT EXISTS per table name, so each table is created once even when several repositories share it or statements run concurrently.

Inherited from​

PostgresStore.tablesReady


writeMutex​

protected readonly writeMutex: AsyncMutex

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:119

Serializes the statements and transactions of a single (not pooled) connection


createConfiguration?​

static optional createConfiguration?: (params) => any

Defined in: packages/core/lib/services/iservice.d.ts:35

Create configuration set by the application on load

Parameters​

params​

any

Returns​

any

Inherited from​

PostgresStore.createConfiguration


filterConfiguration?​

static optional filterConfiguration?: (params) => any

Defined in: packages/core/lib/services/iservice.d.ts:39

Create configuration set by the application on load

Parameters​

params​

any

Returns​

any

Inherited from​

PostgresStore.filterConfiguration


Parameters​

static Parameters: typeof ServiceParameters

Defined in: packages/core/lib/services/service.d.ts:46

Service parameters

Inherited from​

PostgresStore.Parameters

Methods​

__clean()​

__clean(): Promise<void>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:293

Delete every row of every table of the plan (tests), in one transaction: the deferred foreign keys of a cycle are checked once every row is gone

Returns​

Promise<void>

Overrides​

PostgresStore.__clean


acquireMigrationLease()​

protected acquireMigrationLease(name, leaseDuration?): Promise<MigrationLease>

Defined in: packages/core/lib/stores/store.d.ts:501

Take the lease of a migration: free, or expired (a crashed runner)

Parameters​

name​

string

migration name

leaseDuration?​

number

lease duration in ms

Returns​

Promise<MigrationLease>

the lease

Throws​

MigrationAlreadyRunning when another runner holds a live lease

Inherited from​

PostgresStore.acquireMigrationLease


addListener()​

addListener<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:87

Add listener

Type Parameters​

Key​

Key extends keyof StoreEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void | Promise<void>

the event listener

Returns​

this

this for chaining

See​

EventEmitter.addListener

Inherited from​

PostgresStore.addListener


addRoute()​

protected addRoute(url, methods, executer, openapi?, override?): void

Defined in: packages/core/lib/services/service.d.ts:177

Add a route dynamicaly

Parameters​

url​

string

of the route can contains dynamic part like {uuid}

methods​

HttpMethodType[]

the HTTP methods

executer​

Function

Method to execute for this route

openapi?​

OpenAPIWebdaDefinition

the OpenAPI specification

override?​

boolean

whether to override existing

Returns​

void

Inherited from​

PostgresStore.addRoute


authorizeClientEvent()​

authorizeClientEvent(_event, _context): boolean

Defined in: packages/core/lib/services/service.d.ts:153

Authorize a public event subscription

Parameters​

_event​

string

the event name

_context​

OperationContext

the execution context

Returns​

boolean

true if the condition is met

Inherited from​

PostgresStore.authorizeClientEvent


backfillTypes()​

backfillTypes(): Promise<number>

Defined in: packages/sql/lib/store.d.ts:187

Stamp __type on the rows written before stamping, with the model each table was declared for

Idempotent: run it once after upgrading, before relying on the class filter of shared tables (rows without __type are read as the table model until then).

Returns​

Promise<number>

the number of rows stamped

Inherited from​

PostgresStore.backfillTypes


begin()​

begin(_context, operation?): Promise<void>

Defined in: packages/sql/lib/store.d.ts:133

Take part in the transaction of an operation: nothing is opened until the first statement

Parameters​

_context​

Context

the execution context

operation?​

OperationDefinition

the operation, its transaction: false keeps the store out

Returns​

Promise<void>

Inherited from​

PostgresStore.begin


checkKeys()​

checkKeys(): void

Defined in: packages/core/lib/stores/store.d.ts:596

Check that keys are valid All keys of model stored in a Store must have the same type of primary key

Returns​

void

Inherited from​

PostgresStore.checkKeys


checkRawTable()​

protected checkRawTable(table): void

Defined in: packages/sql/lib/store.d.ts:227

Refuse a table this store does not manage: the name is written in the statements

Parameters​

table​

string

the table name

Returns​

void

Inherited from​

PostgresStore.checkRawTable


checkSingleTable()​

protected checkSingleTable(table): void

Defined in: packages/core/lib/stores/store.d.ts:476

Refuse a table that is not the single table of this store

Parameters​

table​

string

the requested table

Returns​

void

Inherited from​

PostgresStore.checkSingleTable


checkStoredTypes()​

checkStoredTypes(): Promise<TypeCheckSummary | undefined>

Defined in: packages/core/lib/stores/store.d.ts:572

Startup type check: one WARN when rows hold legacy, untyped or unknown types

Returns​

Promise<TypeCheckSummary | undefined>

the summary, undefined when disabled or the store has no raw access

Inherited from​

PostgresStore.checkStoredTypes


checkTable()​

checkTable(): Promise<void>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:241

Bring the database to the plan (schemaSync), once at init: under the advisory lock, the live versions are read from the registry and checked, the DDL runs, this version is registered

Returns​

Promise<void>

Overrides​

PostgresStore.checkTable


checkTransactionSupport()​

protected checkTransactionSupport(): void

Defined in: packages/postgres/src/postgresstore.service.ts:143

A transaction needs a connection of its own: a single shared client cannot run concurrent transactions

Returns​

void

Inherited from​

PostgresStore.checkTransactionSupport


commit()​

commit(_context): Promise<void>

Defined in: packages/sql/lib/store.d.ts:138

Commit the transaction of the operation, when a statement opened it

Parameters​

_context​

Context

the execution context

Returns​

Promise<void>

Inherited from​

PostgresStore.commit


competingMigrationLease()​

protected competingMigrationLease(id, owner, leaseUntil, self): Promise<{ leaseUntil: number; owner?: string; } | undefined>

Defined in: packages/core/lib/stores/store.d.ts:511

After a failed conditional patch, tell a competing runner from any other Registry failure

Parameters​

id​

string

Registry entry of the migration

owner​

string | undefined

lease owner the patch expected

leaseUntil​

number

lease end the patch expected

self​

string

owner of this runner: a lease it holds is not a competitor's

Returns​

Promise<{ leaseUntil: number; owner?: string; } | undefined>

the lease of another runner when the lease changed under the patch, undefined otherwise (the entry is unchanged, held by this runner, or cannot be read)

Inherited from​

PostgresStore.competingMigrationLease


computeParameters()​

computeParameters(): void

Defined in: packages/core/lib/stores/store.d.ts:415

Retrieve the Models and build the models hierarchy map.

Walks parameters.models[] (the canonical flat list introduced in Task 1). If the list is empty or contains only the default "Webda/RegistryEntry" fallback, the hierarchy stays empty and the store will not claim any model — preserving the pre-migration fallback behaviour for test-only or misconfigured stores.

Returns​

void

Inherited from​

PostgresStore.computeParameters


countStoredTypes()​

countStoredTypes(_maxRows): Promise<StoredTypeCounts>

Defined in: packages/sql/lib/store.d.ts:242

Exact counts with one GROUP BY per table: never truncated

Parameters​

_maxRows​

number

Returns​

Promise<StoredTypeCounts>

Inherited from​

PostgresStore.countStoredTypes


createDialect()​

protected createDialect(): PostgresRelationalDialect

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:122

Returns​

PostgresRelationalDialect

Overrides​

PostgresStore.createDialect


createRepository()​

protected createRepository<T>(model, _table, _tableModel): RelationalRepository<T>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:262

Type Parameters​

T​

T extends ModelClass<Storable<any, any>>

Parameters​

model​

T

_table​

string

_tableModel​

string | undefined

Returns​

RelationalRepository<T>

Overrides​

PostgresStore.createRepository


createViews()​

createViews(): Promise<void>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:278

Typed tables need no views

Returns​

Promise<void>

Overrides​

PostgresStore.createViews


deleteMigrationProgress()​

deleteMigrationProgress(name): Promise<void>

Defined in: packages/core/lib/stores/store.d.ts:493

Forget the progress of a migration: the next run starts over

Parameters​

name​

string

migration name

Returns​

Promise<void>

Inherited from​

PostgresStore.deleteMigrationProgress


emit()​

emit<Key>(event, data): Promise<void>

Defined in: packages/core/lib/services/service.d.ts:213

Emit the event with data and wait for Promise to finish if listener returned a Promise

Type Parameters​

Key​

Key extends keyof StoreEvents

Parameters​

event​

Key

the event name

data​

StoreEvents[Key]

the data to process

Returns​

Promise<void>

Inherited from​

PostgresStore.emit


enlistTransaction()​

protected enlistTransaction(): void

Defined in: packages/sql/lib/store.d.ts:122

Create the transaction state of this store in the current transaction, unless it has one already

Returns​

void

Inherited from​

PostgresStore.enlistTransaction


ensureTable()​

ensureTable(): Promise<void>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:249

The DDL ran at init

Returns​

Promise<void>

Overrides​

PostgresStore.ensureTable


getAggregationOptions()​

getAggregationOptions(): Partial<AggregationOptions>

Defined in: packages/core/lib/stores/store.d.ts:602

Aggregation options applied to the repositories of this store

Returns​

Partial<AggregationOptions>

the options; undefined values keep the repository defaults

Inherited from​

PostgresStore.getAggregationOptions


getCapabilities()​

getCapabilities(): Record<string, any>

Defined in: packages/core/lib/services/iservice.d.ts:72

Return the capabilities of this service.

By default returns capabilities detected at compile-time from

Returns​

Record<string, any>

the result

Webda Capability-tagged​

interfaces in webda.module.json.

Override to disable capabilities based on configuration:

getCapabilities() {
const caps = super.getCapabilities();
if (!this.parameters.enabled) delete caps["request-filter"];
return caps;
}

Inherited from​

PostgresStore.getCapabilities


getClient()​

getClient(): Client | Pool

Defined in: packages/postgres/src/postgresstore.service.ts:243

Return the postgresql client

Returns​

Client | Pool

the pg client or pool

Inherited from​

PostgresStore.getClient


getClientEvents()​

getClientEvents(): string[]

Defined in: packages/core/lib/services/service.d.ts:144

Return the events that an external system can subscribe to

Returns​

string[]

the list of results

Inherited from​

PostgresStore.getClientEvents


getIsolationLevel()​

protected getIsolationLevel(): PostgresIsolationLevel

Defined in: packages/postgres/src/postgresstore.service.ts:192

Get the isolation level of the transactions, checked: it is written in the BEGIN statement

Returns​

PostgresIsolationLevel

the isolation level of the transactions, checked: it is written in the BEGIN statement

Throws​

WebdaError.CodeError for an unknown level

Inherited from​

PostgresStore.getIsolationLevel


getMaxListeners()​

getMaxListeners(): number

Defined in: packages/core/lib/events/asynceventemitter.d.ts:91

Returns​

number

Inherited from​

PostgresStore.getMaxListeners


getMetric()​

getMetric<T>(type, configuration): T

Defined in: packages/core/lib/services/service.d.ts:138

Add service name label

Type Parameters​

T​

T = Counter<string> | Histogram<string> | Gauge<string>

Parameters​

type​

CustomConstructor<T, [MetricConfiguration<T>]>

the type to look up

configuration​

MetricConfiguration<T>

the configuration

Returns​

T

the result

Inherited from​

PostgresStore.getMetric


getMigrationProgress()​

getMigrationProgress(name): Promise<MigrationProgress | undefined>

Defined in: packages/core/lib/stores/store.d.ts:488

Get the stored progress, undefined when the migration never ran

Parameters​

name​

string

migration name

Returns​

Promise<MigrationProgress | undefined>

the stored progress, undefined when the migration never ran

Inherited from​

PostgresStore.getMigrationProgress


getModels()​

getModels(): ModelClass<Storable<any, any>>[]

Defined in: packages/core/lib/stores/store.d.ts:444

All models managed by this store.

Returns​

ModelClass<Storable<any, any>>[]

the array of model classes managed by this store

Inherited from​

PostgresStore.getModels


getName()​

getName(): string

Defined in: packages/core/lib/services/service.d.ts:218

Get service name

Returns​

string

the result string

Inherited from​

PostgresStore.getName


getOpenApiReplacements()​

getOpenApiReplacements(): any

Defined in: packages/core/lib/services/service.d.ts:182

Return variables for replacement in openapi

Returns​

any

the result

Inherited from​

PostgresStore.getOpenApiReplacements


getOperationId()​

getOperationId(id): string | undefined

Defined in: packages/core/lib/services/service.d.ts:167

If undefined is returned it cancel the operation registration

Parameters​

id​

string

the identifier

Returns​

string | undefined

the result

Inherited from​

PostgresStore.getOperationId


getParameters()​

getParameters(): K

Defined in: packages/core/lib/services/service.d.ts:82

Get the service parameters

Returns​

K

the result

Inherited from​

PostgresStore.getParameters


getQueryMonitorOptions()​

getQueryMonitorOptions(): QueryMonitorOptions

Defined in: packages/core/lib/stores/store.d.ts:420

Query monitor options applied to the repositories of this store

Returns​

QueryMonitorOptions

the options for repository query monitoring

Inherited from​

PostgresStore.getQueryMonitorOptions


getRawTables()​

getRawTables(): RawTable[]

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:284

No Webda 3 JSON rows in a relational table

Returns​

RawTable[]

Overrides​

PostgresStore.getRawTables


getRepositories()​

getRepositories(): PostgresRepository<any>[]

Defined in: packages/postgres/src/postgresstore.service.ts:252

Return the underlying PostgresRepository for each model this store manages, unwrapping the EventRepository produced by getRepository.

Returns​

PostgresRepository<any>[]

the per-model PostgresRepository instances

Inherited from​

PostgresStore.getRepositories


getRepository()​

getRepository<T>(model): Repository<T>

Defined in: packages/sql/lib/store.d.ts:211

Build and return a repository for the given model, using the per-model table name resolved by resolveTable. The repository ensures its table exists (see ensureTable) before its first statement.

The result is cached per model class via @InstanceCache, and may be requested before init() (Store.computeStores runs from the first store to initialize): the repository reads the client on each statement, so it follows the one connected by init() and the reconnection after a stop().

Type Parameters​

T​

T extends ModelClass<Storable<any, any>>

Parameters​

model​

T

the model class

Returns​

Repository<T>

a repository backed by this store's connection

Inherited from​

PostgresStore.getRepository


getSchemaPlan()​

getSchemaPlan(): RelationalSchemaPlan

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:140

The relational plan of the store, built once from the model metadata

Returns​

RelationalSchemaPlan

the plan


getService()​

getService<T>(name): ServicesMap[T]

Defined in: packages/core/lib/services/service.d.ts:131

Get a service by name

Type Parameters​

T​

T extends keyof ServicesMap

Parameters​

name​

T

the name to use

Returns​

ServicesMap[T]

the result map

Deprecated​

Use useService, might reconsider

Inherited from​

PostgresStore.getService


getState()​

getState(): ServiceStates

Defined in: packages/core/lib/services/service.d.ts:55

Get the current state

Returns​

ServiceStates

the result

Inherited from​

PostgresStore.getState


getTableRoot()​

protected getTableRoot(): ModelClass<Storable<any, any>> | undefined

Defined in: packages/core/lib/stores/store.d.ts:471

Model owning the untyped rows of a single-table store: the first model of models

Returns​

ModelClass<Storable<any, any>> | undefined

the model, undefined when unknown

Inherited from​

PostgresStore.getTableRoot


getTransactionClient()​

getTransactionClient(): SQLClient | undefined

Defined in: packages/sql/lib/store.d.ts:118

The client of the transaction the current async chain runs in (an operation or withTransaction)

Statements on it open the transaction connection on first use.

Returns​

SQLClient | undefined

the client, undefined outside a transaction of this store

Inherited from​

PostgresStore.getTransactionClient


getTransactionState()​

protected getTransactionState(): SQLTransactionState | undefined

Defined in: packages/sql/lib/store.d.ts:111

Get the transaction state of this store in the current async chain, while active

Returns​

SQLTransactionState | undefined

the transaction state of this store in the current async chain, while active

Inherited from​

PostgresStore.getTransactionState


getUrl()​

getUrl(url, _methods): string

Defined in: packages/core/lib/services/service.d.ts:161

Return the full path url based on parameters

Parameters​

url​

string

relative url to service

_methods​

HttpMethodType[]

in case we need filtering (like Store)

Returns​

string

absolute url or undefined if need to skip the Route

Inherited from​

PostgresStore.getUrl


handleModel()​

handleModel(model): number

Defined in: packages/core/lib/stores/store.d.ts:591

Return if a model is handled by the store

Parameters​

model​

ModelClass<Storable<any, any>> | Model

the model to use

Returns​

number

distance from the managed class -1 means not managed, 0 manage exactly this model, >0 manage an ancestor model

Inherited from​

PostgresStore.handleModel


import()​

import(models?, source?, purge?): Promise<number>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:339

Import the rows of models from a JSONB store (importFromJsonb)

Parameters​

models?​

string = ""

comma-separated model identifiers, every table root of the plan by default

source?​

string = "Registry"

the JSONB store holding the rows

purge?​

boolean = false

delete the imported rows from the source once committed

Returns​

Promise<number>

0

Throws​

WebdaError.CodeError RELATIONAL_IMPORT_SOURCE when the source is not a PostgresStore


importFromJsonb()​

importFromJsonb(source, options?): Promise<ImportReport[]>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:311

Promote models from a JSONB store: their rows are imported in the relational tables in one transaction, then deleted from the source when purge is set. The models must already be listed in models, and their relational table must not be the JSONB one (name one of them with tables)

Parameters​

source​

SQLStore<any>

the JSONB store holding the rows

options?​

the models (every table root by default) and whether to purge the source

models?​

string[]

the model identifiers

purge?​

boolean

delete the imported rows from the source after the commit

Returns​

Promise<ImportReport[]>

one report per model


init()​

init(): Promise<PostgresRelationalStore<K>>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:219

A schema refused by the live versions or an unreachable registry stops the application

Returns​

Promise<PostgresRelationalStore<K>>

Overrides​

PostgresStore.init


initMetrics()​

initMetrics(): void

Defined in: packages/core/lib/stores/store.d.ts:439

Returns​

void

Inherited from​

PostgresStore.initMetrics


initOperations()​

initOperations(): void

Defined in: packages/core/lib/services/service.d.ts:195

Init the operations from

Returns​

void

Operation​

decorators on this service

Inherited from​

PostgresStore.initOperations


jsonTableOf()​

jsonTableOf(store, model): string | undefined

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:151

The JSONB table of a model served by a PostgresStore on the same server and database, with a table per model (foreignKeysToJsonb)

Parameters​

store​

Store<StoreParameters, StoreEvents> | undefined

the store serving the model

model​

ModelClass

the model

Returns​

string | undefined

the table, undefined when no foreign key can reference it


listeners()​

listeners(eventName): Function[]

Defined in: packages/core/lib/events/asynceventemitter.d.ts:151

Get all listeners for an event

Parameters​

eventName​

keyof StoreEvents

the event name

Returns​

Function[]

the list of results

Inherited from​

PostgresStore.listeners


loadCapabilities()​

protected loadCapabilities(): void

Defined in: packages/core/lib/services/service.d.ts:120

Load capabilities from webda.module.json metadata into _compiledCapabilities.

Called during resolve after dependency injection. Reads the service's type name from parameters, looks it up in the application's module metadata (moddas or beans section), and populates _compiledCapabilities with an empty object for each declared capability name.

Fails silently if the application is not available (e.g., in unit tests where services are instantiated without a full application context).

Returns​

void

Example​

// If webda.module.json contains:
// { "moddas": { "MyApp/HawkService": { "capabilities": ["request-filter", "cors-filter"] } } }
// Then after resolve(), this.getCapabilities() returns:
// { "request-filter": {}, "cors-filter": {} }

See​

getCapabilities

Inherited from​

PostgresStore.loadCapabilities


log()​

log(level, ...args): void

Defined in: packages/core/lib/services/service.d.ts:236

Log operation

Parameters​

level​

WorkerLogLevel

to log

args​

...any[]

additional arguments

Returns​

void

Inherited from​

PostgresStore.log


logSlowQuery()​

logSlowQuery(info): void

Defined in: packages/core/lib/stores/store.d.ts:430

Log a slow query and emit the Store.SlowQuery event

Parameters​

info​

QueryExecutionInfo

execution details of the query

Returns​

void

Inherited from​

PostgresStore.logSlowQuery


migrate()​

migrate(dryRun?, batch?, allowUnknown?): Promise<number>

Defined in: packages/postgres/src/postgresstore.service.ts:267

Rewrite the Webda 3 types of the store to their Webda 4 identifiers

Parameters​

dryRun?​

boolean = false

only count the rows to migrate, write nothing

batch?​

number = 500

rows per page

allowUnknown?​

boolean = false

exit with 0 even when rows keep an unknown or ambiguous type

Returns​

Promise<number>

the exit code

Inherited from​

PostgresStore.migrate


migrateCommand()​

migrateCommand(dryRun?, batch?, allowUnknown?): Promise<number>

Defined in: packages/core/lib/stores/store.d.ts:583

Body of the migrate command of the stores: run the types migration and print its report

Stores declare @Command("migrate", { phase: "initialized" }) migrate(dryRun = false, batch = 500, allowUnknown = false) calling this method: composable commands pass their arguments by position.

Parameters​

dryRun?​

boolean

count, write nothing

batch?​

number

rows per page

allowUnknown?​

boolean

exit with 0 even when rows keep an unknown or ambiguous type

Returns​

Promise<number>

the exit code

Inherited from​

PostgresStore.migrateCommand


migrateTypes()​

migrateTypes(options?): Promise<MigrationReport>

Defined in: packages/core/lib/stores/store.d.ts:559

Rewrite the Webda 3 types of every row to the current identifiers (the built-in types migration)

Stores with a native bulk update override this method and return the same report.

Parameters​

options?​

MigrationOptions

batch size, dry run, lease duration

Returns​

Promise<MigrationReport>

the report

Inherited from​

PostgresStore.migrateTypes


migration()​

migration(name, patcher, options?): Promise<MigrationReport>

Defined in: packages/core/lib/stores/store.d.ts:545

Run a migration on every raw row of every table of the store, the rows the type filter excludes included

Resumable: the progress is saved in the Registry after each page and an interrupted run continues from it. Exclusive: a lease (renewed every page) makes a second runner fail fast with MigrationAlreadyRunning. Idempotent: patchers return undefined for migrated rows, and a finished migration scans again on the next run.

Parameters​

name​

string

migration name

patcher​

MigrationPatcher

computes the patch of a row

options?​

MigrationOptions

batch size, dry run, lease duration

Returns​

Promise<MigrationReport>

the report

Inherited from​

PostgresStore.migration


migrationId()​

protected migrationId(name): string

Defined in: packages/core/lib/stores/store.d.ts:482

Return the Registry entry of the migration

Parameters​

name​

string

migration name

Returns​

string

the Registry entry of the migration

Inherited from​

PostgresStore.migrationId


off()​

off<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:127

Perform off

Type Parameters​

Key​

Key extends keyof StoreEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.off

Inherited from​

PostgresStore.off


on()​

on<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:111

Perform on

Type Parameters​

Key​

Key extends keyof StoreEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.once

Inherited from​

PostgresStore.on


once()​

once<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:103

Perform once

Type Parameters​

Key​

Key extends keyof StoreEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.once

Inherited from​

PostgresStore.once


onQueryExecuted()​

onQueryExecuted(info): void

Defined in: packages/core/lib/stores/store.d.ts:425

Handle query execution reported by a repository

Parameters​

info​

QueryExecutionInfo

the execution information

Returns​

void

Inherited from​

PostgresStore.onQueryExecuted


openTransaction()​

protected openTransaction(): Promise<SQLTransactionConnection>

Defined in: packages/postgres/src/postgresstore.service.ts:156

Check a pool connection out and BEGIN on it

Returns​

Promise<SQLTransactionConnection>

Inherited from​

PostgresStore.openTransaction


operationSchemaName()​

protected operationSchemaName(method, side): string

Defined in: packages/core/lib/services/service.d.ts:191

Schema of an operation side: <service name>.<method>.<side> when the application knows it, else the one the build writes, <class>.<method>.<side>, for the class or its nearest ancestor that has it (a service configured under another name than its class)

Parameters​

method​

string

the method name

side​

"input" | "output"

input or output

Returns​

string

the schema name

Inherited from​

PostgresStore.operationSchemaName


ownTransactionState()​

protected ownTransactionState(): SQLTransactionState | undefined

Defined in: packages/sql/lib/store.d.ts:127

Return the transaction state created by this store in the current transaction

Returns​

SQLTransactionState | undefined

the transaction state created by this store in the current transaction

Inherited from​

PostgresStore.ownTransactionState


rawPages()​

rawPages(table, batchSize, token?): Promise<RawPage>

Defined in: packages/sql/lib/store.d.ts:232

Rows ordered by key, the token is the last key of the page

Parameters​

table​

string

batchSize​

number

token?​

string

Returns​

Promise<RawPage>

Inherited from​

PostgresStore.rawPages


rawPatch()​

rawPatch(table, key, patch): Promise<void>

Defined in: packages/sql/lib/store.d.ts:237

Merge the fields into the row: one statement, no read

Parameters​

table​

string

key​

string

patch​

RawPatch

Returns​

Promise<void>

Inherited from​

PostgresStore.rawPatch


releaseMigrationLease()​

protected releaseMigrationLease(lease, update?): Promise<void>

Defined in: packages/core/lib/stores/store.d.ts:533

Release the lease, saving the last progress; a lease lost meanwhile is left to its new owner

Parameters​

lease​

MigrationLease

the lease

update?​

Partial<MigrationProgress>

progress fields to set

Returns​

Promise<void>

Throws​

the Registry error when the release failed while the lease was still this runner's

Inherited from​

PostgresStore.releaseMigrationLease


removeAllListeners()​

removeAllListeners<Key>(eventName?): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:134

Remove all listeners

Type Parameters​

Key​

Key extends keyof StoreEvents

Parameters​

eventName?​

Key

the event name

Returns​

this

this for chaining

See​

EventEmitter.removeAllListeners

Inherited from​

PostgresStore.removeAllListeners


removeListener()​

removeListener<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:119

Remove listener

Type Parameters​

Key​

Key extends keyof StoreEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.removeListener

Inherited from​

PostgresStore.removeListener


renewMigrationLease()​

protected renewMigrationLease(lease): Promise<void>

Defined in: packages/core/lib/stores/store.d.ts:526

Renew the lease before writing a page

Parameters​

lease​

MigrationLease

the lease

Returns​

Promise<void>

Inherited from​

PostgresStore.renewMigrationLease


resolve()​

resolve(): this

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:130

The Registry must accept any model: a typed schema cannot be the catch-all store

Returns​

this

Overrides​

PostgresStore.resolve


resolveTable()​

resolveTable(model): string

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:252

Parameters​

model​

ModelClass

Returns​

string

Overrides​

PostgresStore.resolveTable


resolveTableModel()​

resolveTableModel(model): string | undefined

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:257

Parameters​

model​

ModelClass

Returns​

string | undefined

Overrides​

PostgresStore.resolveTableModel


rollback()​

rollback(_context, error): Promise<void>

Defined in: packages/sql/lib/store.d.ts:144

Roll back the transaction of the operation, when a statement opened it

Parameters​

_context​

Context

the execution context

error​

unknown

the error failing the operation

Returns​

Promise<void>

Inherited from​

PostgresStore.rollback


saveMigrationProgress()​

protected saveMigrationProgress(lease, update): Promise<void>

Defined in: packages/core/lib/stores/store.d.ts:521

Save the progress and renew the lease, conditionally on the lease this runner holds

Parameters​

lease​

MigrationLease

the lease

update​

Partial<MigrationProgress>

progress fields to set

Returns​

Promise<void>

Throws​

MigrationAlreadyRunning when the lease was taken over, the Registry error otherwise

Inherited from​

PostgresStore.saveMigrationProgress


schema()​

schema(sql?, diff?, json?): Promise<number>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:375

Print the relational schema plan, its DDL or the differences with the database

Parameters​

sql?​

boolean = false

print the CREATE statements of the whole plan

diff?​

boolean = false

connect and print the statements alter would run, then the differences it never resolves

json?​

boolean = false

print the plan as JSON

Returns​

Promise<number>

0, 1 when diff found differences the store cannot resolve


schemaBackfill()​

schemaBackfill(table, from, to, batch?): Promise<number>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:460

Copy a column into another one where the target is null (the expand step of a rename or a type change)

Parameters​

table​

string

the table

from​

string

the source column

to​

string

the target column

batch?​

number = 1000

rows per statement

Returns​

Promise<number>

0


schemaCheck()​

schemaCheck(against?, forceIncompatible?, json?): Promise<number>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:400

Compare the plan with the live versions of the registry (CI: fail before deploy, not at startup)

Parameters​

against?​

string

compare with one version (identifier, application version or plan hash) instead of the live ones

forceIncompatible?​

boolean = false

downgrade every blocking change to a warning

json?​

boolean = false

print the changes as JSON

Returns​

Promise<number>

0, 1 when a change blocks, 2 when against matches no version


schemaContract()​

schemaContract(dryRun?): Promise<number>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:421

Apply (or print) what no live version uses any more: drop the unused columns and tables, SET NOT NULL where every live version requires the field and no row is null, validate the foreign keys. Never run by init()

Parameters​

dryRun?​

boolean = false

print the statements without running them

Returns​

Promise<number>

0


schemaRetire()​

schemaRetire(version): Promise<number>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:441

Retire a version: it no longer counts for the compatibility checks and the contract phase

Parameters​

version​

string

its identifier, application version or plan hash

Returns​

Promise<number>

0, 1 when no version matches


setMaxListeners()​

setMaxListeners(n): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:95

Parameters​

n​

number

Returns​

this

Inherited from​

PostgresStore.setMaxListeners


setModelDefinitionHelper()​

setModelDefinitionHelper(model): void

Defined in: packages/core/lib/stores/store.d.ts:370

Override the resolved model class for this store at runtime. Used by the abstract StoreTest harness so test fixtures can substitute a subclass with extra fields in place of the configured model. In production this is a no-op the framework never calls.

Parameters​

model​

ModelClass

the substitute model class

Returns​

void

Inherited from​

PostgresStore.setModelDefinitionHelper


statementClient()​

protected statementClient(): SQLClient | undefined

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:186

The client the repositories run their statements on: the connection of the transaction of the current async chain (an operation with transaction: "operation", withTransaction) when there is one, else the pool, or the single client under the same lock as the transactions, so a plain write never lands inside another caller's transaction

Returns​

SQLClient | undefined

the client, undefined while the store is not connected


stop()​

stop(): Promise<void>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:231

Stop the version heartbeat

Returns​

Promise<void>

Overrides​

PostgresStore.stop


tableRootOf()​

protected tableRootOf(table): any

Defined in: packages/sql/lib/store.d.ts:179

The first model of models stored in a table

Parameters​

table​

string

the table name

Returns​

any

the model, undefined when no configured model is stored in it

Inherited from​

PostgresStore.tableRootOf


toJSON()​

toJSON(): string

Defined in: packages/core/lib/services/service.d.ts:200

Prevent service to be serialized

Returns​

string

the result

Inherited from​

PostgresStore.toJSON


toString()​

toString(): string

Defined in: packages/core/lib/services/service.d.ts:91

Return service representation

Returns​

string

the result

Inherited from​

PostgresStore.toString


transact()​

transact<R>(fn): Promise<R>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:204

Run statements in one transaction: the transaction of the current async chain when there is one, else one of its own on a pooled connection, or serialized on the single client

Type Parameters​

R​

R

Parameters​

fn​

(tx) => Promise<R>

the statements

Returns​

Promise<R>

the function result


transactionKey()​

protected transactionKey(): string

Defined in: packages/sql/lib/store.d.ts:95

Key of the transaction state in the operation transaction: stores sharing one connection share it

Returns​

string

the key

Inherited from​

PostgresStore.transactionKey


typesPatcher()​

protected typesPatcher(): MigrationPatcher

Defined in: packages/core/lib/stores/store.d.ts:551

Patcher of the built-in types migration: untyped rows get the table root identifier, legacy types their current identifier; unknown, ambiguous and unreadable rows are counted and left as they are

Returns​

MigrationPatcher

the patcher

Inherited from​

PostgresStore.typesPatcher


withConnection()​

protected withConnection<R>(fn): Promise<R>

Defined in: packages/postgres/src/postgresrelationalstore.service.ts:167

Run statements on one connection: a connection of the pool, or the client

Type Parameters​

R​

R

Parameters​

fn​

(client) => Promise<R>

the statements

Returns​

Promise<R>

the function result


withTransaction()​

withTransaction<T>(fn): Promise<T>

Defined in: packages/sql/lib/store.d.ts:153

Run a function in a transaction of this store, for code outside operations (CLI, queue workers, tests)

Committed when the function resolves, rolled back when it throws. Inside an operation or another transaction, the store joins it: the work is committed with it. Works whatever the transaction mode.

Type Parameters​

T​

T

Parameters​

fn​

() => Promise<T>

the function

Returns​

Promise<T>

the function result

Inherited from​

PostgresStore.withTransaction


claimingStore()​

static claimingStore(model, stores?): Store<StoreParameters, StoreEvents> | undefined

Defined in: packages/core/lib/stores/store.d.ts:387

The store listing a model (or its closest ancestor) in its models

Parameters​

model​

ModelClass

the model

stores?​

Store<StoreParameters, StoreEvents>[]

the candidate stores, every store of the application by default

Returns​

Store<StoreParameters, StoreEvents> | undefined

the store, undefined when none lists it (the Registry serves it)

Inherited from​

PostgresStore.claimingStore


computeStores()​

static computeStores(): void

Defined in: packages/core/lib/stores/store.d.ts:405

Compute and register repositories for all known models based on available stores.

Called from Store.init() so each store's init triggers a recompute. Cannot be cached: the FIRST store to init (typically Registry) would claim every model with its fallback repository, and subsequent stores wouldn't get a chance to claim their configured models. Re-running is idempotent — registerRepository overwrites map entries in place, and the resolution loop is deterministic per current service/model state.

Returns​

void

Inherited from​

PostgresStore.computeStores


storeOf()​

static storeOf(model): Store<StoreParameters, StoreEvents> | undefined

Defined in: packages/core/lib/stores/store.d.ts:393

The store serving a model: the one listing it, else the Registry

Parameters​

model​

ModelClass

the model

Returns​

Store<StoreParameters, StoreEvents> | undefined

the store, undefined before the Registry exists

Inherited from​

PostgresStore.storeOf