PostgresStore
Class: PostgresStore<K>
Defined in: postgres/src/postgresstore.service.ts:92
Store data within PostgreSQL with JSONB
The table should be created before with
CREATE TABLE IF NOT EXISTS ${tableName}
(
uuid uuid NOT NULL,
data jsonb,
CONSTRAINT ${tableName}_pkey PRIMARY KEY (uuid)
);
Webda Modda
Extends
SQLStore<K>
Type Parameters
K
K extends PostgresParameters = PostgresParameters
Constructors
Constructor
new PostgresStore<
K>(name,params):PostgresStore<K>
Defined in: core/lib/services/service.d.ts:72
Service
Parameters
name
string
The name of the service
params
K
The parameters block define in the configuration file
Returns
PostgresStore<K>
Inherited from
Properties
_compiledCapabilities
protected_compiledCapabilities:Record<string,any>
Defined in: core/lib/services/iservice.d.ts:39
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
SQLStore._compiledCapabilities
_modelMetadatas
_modelMetadatas:
Map<string,ModelMetadata>
Defined in: core/lib/stores/store.d.ts:284
Metadata for each model in _models, keyed by Identifier.
Inherited from
_models
_models:
ModelClass<Storable<any,any>>[]
Defined in: core/lib/stores/store.d.ts:282
All model classes managed by this store. Index 0 is the legacy "primary" model.
Inherited from
_modelsHierarchy
_modelsHierarchy:
object
Defined in: core/lib/stores/store.d.ts:286
Store the manager hierarchy with their depth
Index Signature
[key: string]: number
Inherited from
[WEBDA_EVENTS]
[WEBDA_EVENTS]:
StoreEvents
Defined in: core/lib/services/service.d.ts:50
Set the Webda events here
Inherited from
client
client:
Client|Pool
Defined in: postgres/src/postgresstore.service.ts:93
logger
protectedlogger:Logger
Defined in: core/lib/services/service.d.ts:59
Logger with class context
Inherited from
metrics
metrics:
object
Defined in: core/lib/stores/store.d.ts:302
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
name
readonlyname:string
Defined in: core/lib/services/iservice.d.ts:19
Inherited from
ownsPool
protectedownsPool:boolean=false
Defined in: postgres/src/postgresstore.service.ts:98
True when client is a shared pool acquired from the registry. Tracked so stop only releases pools it took a refcount on.
parameters
readonlyparameters:K
Defined in: core/lib/services/iservice.d.ts:20
Inherited from
tablesReady
protectedtablesReady:Map<string,Promise<void>>
Defined in: postgres/src/postgresstore.service.ts:103
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.
createConfiguration?
staticoptionalcreateConfiguration?: (params) =>any
Defined in: core/lib/services/iservice.d.ts:24
Create configuration set by the application on load
Parameters
params
any
Returns
any
Inherited from
filterConfiguration?
staticoptionalfilterConfiguration?: (params) =>any
Defined in: core/lib/services/iservice.d.ts:28
Create configuration set by the application on load
Parameters
params
any
Returns
any
Inherited from
Parameters
staticParameters: typeofServiceParameters
Defined in: core/lib/services/service.d.ts:46
Service parameters
Inherited from
Methods
__clean()
__clean():
Promise<void>
Defined in: postgres/src/postgresstore.service.ts:343
Delete all rows from all managed tables (used in tests).
Returns
Promise<void>
Overrides
addListener()
addListener<
Key>(eventName,listener):this
Defined in: core/lib/events/asynceventemitter.d.ts:80
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
addRoute()
protectedaddRoute(url,methods,executer,openapi?,override?):void
Defined in: 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
authorizeClientEvent()
authorizeClientEvent(
_event,_context):boolean
Defined in: 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
checkKeys()
checkKeys():
void
Defined in: core/lib/stores/store.d.ts:362
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
checkTable()
checkTable():
Promise<void>
Defined in: postgres/src/postgresstore.service.ts:181
Ensure all managed model tables exist (one per model in the hierarchy).
When autoCreateTable is false, this is a no-op.
Returns
Promise<void>
computeParameters()
computeParameters():
void
Defined in: core/lib/stores/store.d.ts:328
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
createViews()
createViews():
Promise<void>
Defined in: postgres/src/postgresstore.service.ts:277
Create views for each model that is stored in a PostgresStore.
Creates one SQL VIEW per model (or model subclass) that maps the JSONB
data column to typed columns based on the model's stored JSON schema.
Returns
Promise<void>
emit()
emit<
Key>(event,data):Promise<void>
Defined in: core/lib/services/service.d.ts:204
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
ensureTable()
ensureTable(
repo):Promise<void>
Defined in: postgres/src/postgresstore.service.ts:199
Ensure the table backing a repository exists, once per table name.
Repositories await it before their first statement, so models routed to this store
after init (e.g. Registry fallback in Store.computeStores) get their table too.
When autoCreateTable is false, this is a no-op.
Parameters
repo
PostgresRepository<any>
the repository whose table to create
Returns
Promise<void>
getCapabilities()
getCapabilities():
Record<string,any>
Defined in: core/lib/services/iservice.d.ts:61
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
getClient()
getClient():
Client|Pool
Defined in: postgres/src/postgresstore.service.ts:218
Return the postgresql client
Returns
Client | Pool
the pg client or pool
getClientEvents()
getClientEvents():
string[]
Defined in: 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
getMaxListeners()
getMaxListeners():
number
Defined in: core/lib/events/asynceventemitter.d.ts:84
Returns
number
Inherited from
getMetric()
getMetric<
T>(type,configuration):T
Defined in: 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
getModels()
getModels():
ModelClass<Storable<any,any>>[]
Defined in: core/lib/stores/store.d.ts:349
All models managed by this store.
Returns
ModelClass<Storable<any, any>>[]
the array of model classes managed by this store
Inherited from
getName()
getName():
string
Defined in: core/lib/services/service.d.ts:209
Get service name
Returns
string
the result string
Inherited from
getOpenApiReplacements()
getOpenApiReplacements():
any
Defined in: core/lib/services/service.d.ts:182
Return variables for replacement in openapi
Returns
any
the result
Inherited from
SQLStore.getOpenApiReplacements
getOperationId()
getOperationId(
id):string
Defined in: core/lib/services/service.d.ts:167
If undefined is returned it cancel the operation registration
Parameters
id
string
the identifier
Returns
string
the result
Inherited from
getParameters()
getParameters():
K
Defined in: core/lib/services/service.d.ts:82
Get the service parameters
Returns
K
the result
Inherited from
getRepositories()
getRepositories():
PostgresRepository<any>[]
Defined in: postgres/src/postgresstore.service.ts:253
Return the underlying PostgresRepository for each model this store manages, unwrapping the EventRepository produced by getRepository.
Returns
PostgresRepository<any>[]
the per-model PostgresRepository instances
getRepository()
getRepository<
T>(model):Repository<T>
Defined in: postgres/src/postgresstore.service.ts:232
Build and return a PostgresRepository 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.
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 pg connection
Overrides
getService()
getService<
T>(name):ServicesMap[T]
Defined in: 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
getState()
getState():
ServiceStates
Defined in: core/lib/services/service.d.ts:55
Get the current state
Returns
ServiceStates
the result
Inherited from
getUrl()
getUrl(
url,_methods):string
Defined in: 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
handleModel()
handleModel(
model):number
Defined in: core/lib/stores/store.d.ts:357
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
init()
init():
Promise<PostgresStore<K>>
Defined in: postgres/src/postgresstore.service.ts:108
Returns
Promise<PostgresStore<K>>
Overrides
initMetrics()
initMetrics():
void
Defined in: core/lib/stores/store.d.ts:344
Returns
void
Inherited from
initOperations()
initOperations():
void
Defined in: core/lib/services/service.d.ts:186
Init the operations from
Returns
void
Operation
decorators on this service
Inherited from
listeners()
listeners(
eventName):Function[]
Defined in: core/lib/events/asynceventemitter.d.ts:139
Get all listeners for an event
Parameters
eventName
keyof StoreEvents
the event name
Returns
Function[]
the list of results
Inherited from
loadCapabilities()
protectedloadCapabilities():void
Defined in: 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
log()
log(
level, ...args):void
Defined in: core/lib/services/service.d.ts:226
Parameters
level
WorkerLogLevel
to log
args
...any[]
additional arguments
Returns
void
Inherited from
logSlowQuery()
logSlowQuery(
_query,_reason,_time):void
Defined in: core/lib/stores/store.d.ts:335
Log a slow query (placeholder for future implementation)
Parameters
_query
string
the query to execute
_reason
string
the reason
_time
number
the time
Returns
void
Inherited from
off()
off<
Key>(eventName,listener):this
Defined in: core/lib/events/asynceventemitter.d.ts:116
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
on()
on<
Key>(eventName,listener):this
Defined in: core/lib/events/asynceventemitter.d.ts:102
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
once()
once<
Key>(eventName,listener):this
Defined in: core/lib/events/asynceventemitter.d.ts:95
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
removeAllListeners()
removeAllListeners<
Key>(eventName?):this
Defined in: core/lib/events/asynceventemitter.d.ts:122
Type Parameters
Key
Key extends keyof StoreEvents
Parameters
eventName?
Key
the event name
Returns
this
this for chaining
See
EventEmitter.removeAllListeners
Inherited from
removeListener()
removeListener<
Key>(eventName,listener):this
Defined in: core/lib/events/asynceventemitter.d.ts:109
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
resolve()
resolve():
this
Defined in: core/lib/services/service.d.ts:98
Resolve parameters and load metadata. @Route-declared routes are scanned
and registered by Router.discoverRoutes(services) from Core.init()
once every service has resolved — nothing to do per-service here.
Returns
this
the result
Inherited from
resolveTable()
resolveTable(
model):string
Defined in: postgres/src/postgresstore.service.ts:156
Resolve the table name for a given model class.
Resolution order:
parameters.tables[meta.Identifier]— explicit per-model override- Single-model back-compat: when only one model is configured,
parameters.tablemaps to it (and to its subclasses) — not to models routed to this store as fallback - Default — model identifier lowercased with "/" replaced by "_"
Parameters
model
ModelClass
the model class to resolve the table for
Returns
string
the table name
setMaxListeners()
setMaxListeners(
n):this
Defined in: core/lib/events/asynceventemitter.d.ts:88
Parameters
n
number
Returns
this
Inherited from
setModelDefinitionHelper()
setModelDefinitionHelper(
model):void
Defined in: core/lib/stores/store.d.ts:296
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
SQLStore.setModelDefinitionHelper
stop()
stop():
Promise<void>
Defined in: postgres/src/postgresstore.service.ts:130
Returns
Promise<void>
Overrides
toJSON()
toJSON():
string
Defined in: core/lib/services/service.d.ts:191
Prevent service to be serialized
Returns
string
the result
Inherited from
toString()
toString():
string
Defined in: core/lib/services/service.d.ts:91
Return service representation
Returns
string
the result
Inherited from
computeStores()
staticcomputeStores():void
Defined in: core/lib/stores/store.d.ts:318
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