@webda/postgres 4.0.0-beta.2 → 4.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,352 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import { EventRepository, InstanceCache, useApplication, useCore, useModel, useModelMetadata } from "@webda/core";
36
+ import pg from "pg";
37
+ import { acquirePool, releasePool } from "./pgpool.js";
38
+ import { PostgresRepository, SQLStore, SQLStoreParameters } from "./sqlstore.js";
39
+ import { useLog } from "@webda/workout";
40
+ /*
41
+ * Ideas:
42
+ * - Make views for each models to have a better query: https://dba.stackexchange.com/questions/151838/postgresql-json-column-to-view
43
+ * - CREATE VIEW my_view AS SELECT uuid,data->>'status' as status from table;
44
+ * - could auto resolve FK
45
+ * - Use STORED generated model to define FK: https://stackoverflow.com/questions/24489647/json-foreign-keys-in-postgresql
46
+ * - FKs should be defined based on relationship
47
+ * - Define colums dynamically based on the schema -> benchmark to see if it is useful
48
+ * - Allow to define indexes on fields
49
+ */
50
+ /**
51
+ *
52
+ */
53
+ export class PostgresParameters extends SQLStoreParameters {
54
+ /**
55
+ * @override
56
+ * @param params - raw parameters
57
+ * @returns this
58
+ */
59
+ load(params) {
60
+ super.load(params);
61
+ this.autoCreateTable ?? (this.autoCreateTable = true);
62
+ this.usePool ?? (this.usePool = false);
63
+ this.viewPrefix ?? (this.viewPrefix = "");
64
+ this.views ?? (this.views = [".*"]);
65
+ this.tables ?? (this.tables = {});
66
+ return this;
67
+ }
68
+ }
69
+ /**
70
+ * Store data within PostgreSQL with JSONB
71
+ *
72
+ * The table should be created before with
73
+ *
74
+ * ```sql
75
+ * CREATE TABLE IF NOT EXISTS ${tableName}
76
+ * (
77
+ * uuid uuid NOT NULL,
78
+ * data jsonb,
79
+ * CONSTRAINT ${tableName}_pkey PRIMARY KEY (uuid)
80
+ * );
81
+ * ```
82
+ *
83
+ * @WebdaModda
84
+ */
85
+ let PostgresStore = (() => {
86
+ var _a;
87
+ let _classSuper = SQLStore;
88
+ let _instanceExtraInitializers = [];
89
+ let _getRepository_decorators;
90
+ return _a = class PostgresStore extends _classSuper {
91
+ constructor() {
92
+ super(...arguments);
93
+ this.client = __runInitializers(this, _instanceExtraInitializers);
94
+ /**
95
+ * True when {@link client} is a shared pool acquired from the registry.
96
+ * Tracked so {@link stop} only releases pools it took a refcount on.
97
+ */
98
+ this.ownsPool = false;
99
+ /**
100
+ * Pending or completed `CREATE TABLE IF NOT EXISTS` per table name, so each table is
101
+ * created once even when several repositories share it or statements run concurrently.
102
+ */
103
+ this.tablesReady = new Map();
104
+ }
105
+ /**
106
+ * @override
107
+ */
108
+ async init() {
109
+ if (this.parameters.table && (this.parameters.models?.length ?? 0) > 1) {
110
+ useLog("WARN", `PostgresStore "${this.getName()}": parameters.table is ignored when more than one model is configured. Use parameters.tables[id] instead.`);
111
+ }
112
+ if (this.parameters.usePool) {
113
+ this.client = acquirePool(this.parameters.postgresqlServer);
114
+ this.ownsPool = true;
115
+ }
116
+ else {
117
+ this.client = new pg.Client(this.parameters.postgresqlServer);
118
+ await this.client.connect();
119
+ }
120
+ await this.checkTable();
121
+ await super.init();
122
+ return this;
123
+ }
124
+ /**
125
+ * @override
126
+ */
127
+ async stop() {
128
+ if (this.ownsPool) {
129
+ this.ownsPool = false;
130
+ await releasePool(this.parameters.postgresqlServer);
131
+ }
132
+ else if (this.client && "end" in this.client) {
133
+ await this.client.end().catch(() => {
134
+ /* already ended */
135
+ });
136
+ }
137
+ this.client = undefined;
138
+ this.tablesReady.clear();
139
+ await super.stop();
140
+ }
141
+ /**
142
+ * Resolve the table name for a given model class.
143
+ *
144
+ * Resolution order:
145
+ * 1. `parameters.tables[meta.Identifier]` — explicit per-model override
146
+ * 2. Single-model back-compat: when only one model is configured, `parameters.table` maps to it
147
+ * (and to its subclasses) — not to models routed to this store as fallback
148
+ * 3. Default — model identifier lowercased with "/" replaced by "_"
149
+ *
150
+ * @param model - the model class to resolve the table for
151
+ * @returns the table name
152
+ */
153
+ resolveTable(model) {
154
+ const meta = useModelMetadata(model);
155
+ if (!meta) {
156
+ return this.parameters.table;
157
+ }
158
+ // Explicit per-model override
159
+ if (this.parameters.tables?.[meta.Identifier]) {
160
+ return this.parameters.tables[meta.Identifier];
161
+ }
162
+ // Single-model back-compat: parameters.table maps to the one model and its hierarchy
163
+ if (this.parameters.models?.length === 1 &&
164
+ this.parameters.table &&
165
+ (this.parameters.models[0] === meta.Identifier || this.handleModel(model) >= 0)) {
166
+ return this.parameters.table;
167
+ }
168
+ // Default derivation
169
+ return meta.Identifier.toLowerCase().replace(/\//g, "_");
170
+ }
171
+ /**
172
+ * Ensure all managed model tables exist (one per model in the hierarchy).
173
+ * When `autoCreateTable` is false, this is a no-op.
174
+ */
175
+ async checkTable() {
176
+ if (!this.parameters.autoCreateTable) {
177
+ return;
178
+ }
179
+ // Delegate the per-model DDL to each PostgresRepository.setupTable().
180
+ // ensureTable deduplicates by table name so shared-table models don't issue redundant DDL.
181
+ for (const repo of this.getRepositories()) {
182
+ await this.ensureTable(repo);
183
+ }
184
+ }
185
+ /**
186
+ * Ensure the table backing a repository exists, once per table name.
187
+ * Repositories await it before their first statement, so models routed to this store
188
+ * after init (e.g. Registry fallback in Store.computeStores) get their table too.
189
+ * When `autoCreateTable` is false, this is a no-op.
190
+ * @param repo - the repository whose table to create
191
+ */
192
+ async ensureTable(repo) {
193
+ if (!this.parameters.autoCreateTable) {
194
+ return;
195
+ }
196
+ const table = repo.getTable();
197
+ let ready = this.tablesReady.get(table);
198
+ if (!ready) {
199
+ ready = repo.setupTable();
200
+ this.tablesReady.set(table, ready);
201
+ // Allow a retry after a failed creation
202
+ ready.catch(() => this.tablesReady.get(table) === ready && this.tablesReady.delete(table));
203
+ }
204
+ await ready;
205
+ }
206
+ /**
207
+ * Return the postgresql client
208
+ * @returns the pg client or pool
209
+ */
210
+ getClient() {
211
+ return this.client;
212
+ }
213
+ /**
214
+ * Build and return a PostgresRepository for the given model, using the
215
+ * per-model table name resolved by `resolveTable`. The repository ensures its
216
+ * table exists (see {@link ensureTable}) before its first statement.
217
+ *
218
+ * The result is cached per model class via `@InstanceCache`.
219
+ * @param model - the model class
220
+ * @returns a repository backed by this store's pg connection
221
+ */
222
+ getRepository(model) {
223
+ const meta = useModelMetadata(model);
224
+ const table = this.resolveTable(model);
225
+ const inner = new PostgresRepository(model, meta.PrimaryKey, this.client, table, meta.PrimaryKeySeparator, () => this.ensureTable(inner));
226
+ // Wrap in EventRepository so typed CRUD events fire; consumers reach them
227
+ // via useRepository(model).on(...).
228
+ return new EventRepository(model, meta.PrimaryKey, inner, meta.PrimaryKeySeparator);
229
+ }
230
+ /**
231
+ * Return the underlying PostgresRepository for each model this store manages,
232
+ * unwrapping the EventRepository produced by {@link getRepository}.
233
+ * @returns the per-model PostgresRepository instances
234
+ */
235
+ getRepositories() {
236
+ const repos = [];
237
+ for (const modelId of Object.keys(this._modelsHierarchy ?? {})) {
238
+ let model;
239
+ try {
240
+ model = useModel(modelId);
241
+ }
242
+ catch {
243
+ continue;
244
+ }
245
+ if (!model) {
246
+ continue;
247
+ }
248
+ const repo = this.getRepository(model);
249
+ repos.push((repo.repository ?? repo));
250
+ }
251
+ return repos;
252
+ }
253
+ /**
254
+ * Create views for each model that is stored in a PostgresStore.
255
+ *
256
+ * Creates one SQL VIEW per model (or model subclass) that maps the JSONB
257
+ * `data` column to typed columns based on the model's stored JSON schema.
258
+ */
259
+ async createViews() {
260
+ const app = useApplication();
261
+ const models = app.getModels();
262
+ const viewPatterns = (this.parameters.views ?? [".*"]).map(p => new RegExp(p));
263
+ const modelMatches = (identifier) => viewPatterns.some(re => re.test(identifier));
264
+ for (const model of Object.values(models)) {
265
+ if (!model)
266
+ continue;
267
+ const meta = useModelMetadata(model);
268
+ if (!meta || !meta.Identifier)
269
+ continue;
270
+ if (!modelMatches(meta.Identifier))
271
+ continue;
272
+ // Find the PostgresStore responsible for this model
273
+ const allServices = Object.values(useCore().getServices()).filter(s => s instanceof _a);
274
+ const store = allServices.find(s => s.handleModel(model) >= 0);
275
+ if (!store)
276
+ continue;
277
+ const schema = meta.Schemas?.Stored;
278
+ if (!schema || !schema.properties)
279
+ continue;
280
+ const plural = meta.Plural || meta.Identifier.split("/").pop().toLowerCase() + "s";
281
+ const viewName = `${this.parameters.viewPrefix}${plural}`;
282
+ const fields = ["uuid"];
283
+ for (const field of Object.keys(schema.properties)) {
284
+ if (field === "uuid" || !field.match(/^[0-9a-zA-Z-_$]+$/)) {
285
+ continue;
286
+ }
287
+ let cast = "";
288
+ const type = schema.properties[field].type;
289
+ if (type === "number") {
290
+ cast = "::bigint";
291
+ }
292
+ else if (type === "boolean") {
293
+ cast = "::boolean";
294
+ }
295
+ else if (type === "string") {
296
+ cast = "::text";
297
+ }
298
+ else if (type === "array") {
299
+ cast = "::jsonb";
300
+ }
301
+ else if (type === "object") {
302
+ cast = "::jsonb";
303
+ }
304
+ fields.push(`(data->>'${field}')${cast} as ${field}`);
305
+ }
306
+ let query = `CREATE OR REPLACE VIEW ${viewName} AS SELECT ${fields.join(",")} FROM ${store.resolveTable(model)}`;
307
+ if (store.handleModel(model) > 0) {
308
+ query += ` WHERE (data#>>'{__type}') = '${meta.ShortName || meta.Identifier}'`;
309
+ }
310
+ try {
311
+ this.log("INFO", `Dropping view ${viewName}`);
312
+ await store.getClient().query(`DROP VIEW IF EXISTS ${viewName}`);
313
+ this.log("INFO", query);
314
+ await store.getClient().query(query);
315
+ }
316
+ catch (err) {
317
+ this.log("ERROR", err);
318
+ }
319
+ }
320
+ }
321
+ /**
322
+ * Delete all rows from all managed tables (used in tests).
323
+ */
324
+ async __clean() {
325
+ const tables = new Set([this.parameters.table]);
326
+ for (const modelId of Object.keys(this._modelsHierarchy ?? {})) {
327
+ try {
328
+ const model = useModel(modelId);
329
+ if (model) {
330
+ tables.add(this.resolveTable(model));
331
+ }
332
+ }
333
+ catch {
334
+ // skip unreachable models
335
+ }
336
+ }
337
+ for (const table of tables) {
338
+ await this.client.query(`DELETE FROM ${table}`);
339
+ }
340
+ }
341
+ },
342
+ (() => {
343
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
344
+ _getRepository_decorators = [InstanceCache()];
345
+ __esDecorate(_a, null, _getRepository_decorators, { kind: "method", name: "getRepository", static: false, private: false, access: { has: obj => "getRepository" in obj, get: obj => obj.getRepository }, metadata: _metadata }, null, _instanceExtraInitializers);
346
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
347
+ })(),
348
+ _a;
349
+ })();
350
+ export { PostgresStore };
351
+ export default PostgresStore;
352
+ //# sourceMappingURL=postgresstore.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgresstore.service.js","sourceRoot":"","sources":["../src/postgresstore.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGlH,OAAO,EAAgC,MAAM,IAAI,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,kBAAkB;IAqCxD;;;;OAIG;IACH,IAAI,CAAC,MAAW;QACd,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,IAAI,CAAC,eAAe,KAApB,IAAI,CAAC,eAAe,GAAK,IAAI,EAAC;QAC9B,IAAI,CAAC,OAAO,KAAZ,IAAI,CAAC,OAAO,GAAK,KAAK,EAAC;QACvB,IAAI,CAAC,UAAU,KAAf,IAAI,CAAC,UAAU,GAAK,EAAE,EAAC;QACvB,IAAI,CAAC,KAAK,KAAV,IAAI,CAAC,KAAK,GAAK,CAAC,IAAI,CAAC,EAAC;QACtB,IAAI,CAA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AAA,aAAa,6DAcZ;;;;;SA1JU,aAAa;AA6Q1B,eAAe,aAAa,CAAC"}
package/lib/sqlstore.d.ts CHANGED
@@ -1,79 +1,172 @@
1
- import { CoreModel, ModelLink, Store, StoreParameters } from "@webda/core";
1
+ import { MemoryRepository, Store, StoreParameters } from "@webda/core";
2
+ import type { ModelClass, Repository } from "@webda/core";
2
3
  import * as WebdaQL from "@webda/ql";
4
+ /** Database connection metadata */
3
5
  export interface SQLDatabase {
4
6
  name: string;
5
7
  }
8
+ /** Base parameters for SQL-backed stores */
6
9
  export declare class SQLStoreParameters extends StoreParameters {
7
10
  table: string;
8
11
  database: SQLDatabase;
12
+ /**
13
+ * @override
14
+ * @param params - raw parameters
15
+ * @returns this
16
+ */
17
+ load(params: any): this;
9
18
  }
19
+ /** Minimal SQL client interface compatible with pg.Client and pg.Pool */
10
20
  export interface SQLClient {
11
- query: () => Promise<void>;
21
+ query: (q: string, values?: any[]) => Promise<{
22
+ rows: any[];
23
+ rowCount: number;
24
+ }>;
12
25
  }
26
+ /** Typed result wrapper for SQL queries */
13
27
  export interface SQLResult<T> {
14
28
  rows: T[];
15
29
  rowCount: number;
16
30
  }
31
+ /** Extends ComparisonExpression to emit SQL-compatible string literals for JSONB comparisons */
17
32
  export declare class SQLComparisonExpression extends WebdaQL.ComparisonExpression {
33
+ /**
34
+ * Single quotes are doubled so a value can never close the literal. Backslashes stay
35
+ * literal: with `standard_conforming_strings` (PostgreSQL default) `\\` is not an
36
+ * escape character in '...' strings — only LIKE gives it a meaning.
37
+ *
38
+ * @override
39
+ * @param value - the value to stringify
40
+ * @returns SQL-compatible string literal
41
+ */
18
42
  toStringValue(value: (string | number | boolean) | (string | number | boolean)[]): string;
43
+ /**
44
+ * @override
45
+ * @returns SQL attribute expression with type cast
46
+ */
19
47
  toStringAttribute(): string;
20
48
  }
21
- export declare abstract class SQLStore<T extends CoreModel, K extends SQLStoreParameters = SQLStoreParameters> extends Store<T, K> {
22
- sqlQuery(q: string, values?: any[]): Promise<SQLResult<T>>;
49
+ /**
50
+ * PostgreSQL-backed repository for a single model class.
51
+ *
52
+ * Stores every object as a JSONB `data` column alongside a `uuid` primary-key
53
+ * column. All CRUD operations hit the pg client; the inherited MemoryRepository
54
+ * serialize/deserialize helpers are reused for JSON ↔ model-instance
55
+ * conversion.
56
+ */
57
+ /**
58
+ * PostgreSQL-backed repository for a single model class.
59
+ *
60
+ * Stores every object as a JSONB `data` column alongside a `uuid` primary-key
61
+ * column. All CRUD operations hit the pg client; the inherited MemoryRepository
62
+ * serialize/deserialize helpers are reused for JSON to model-instance conversion.
63
+ */
64
+ export declare class PostgresRepository<T extends ModelClass> extends MemoryRepository<T> {
65
+ protected readonly client: SQLClient;
66
+ protected readonly table: string;
67
+ protected readonly prepare?: () => Promise<void>;
23
68
  /**
24
- * Execute a SQL query
25
- * @param q the query
26
- * @param values to be added to the query
69
+ * Create a new PostgresRepository.
70
+ * @param model - the model class
71
+ * @param pks - primary key field names
72
+ * @param client - the pg client or pool
73
+ * @param table - the table name
74
+ * @param separator - composite key separator
75
+ * @param prepare - awaited before every statement (e.g. to ensure the table exists)
27
76
  */
28
- abstract executeQuery(q: string, values?: any[]): Promise<SQLResult<T>>;
77
+ constructor(model: T, pks: string[], client: SQLClient, table: string, separator?: string, prepare?: () => Promise<void>);
29
78
  /**
30
- * Add the SELECT * FROM table if the query is not a full query
31
- * @param q query to complete
32
- * @returns
79
+ * The backing table name for this repository's model.
80
+ * @returns the table name
81
+ * @internal Not part of the @webda/models Repository interface.
33
82
  */
34
- completeQuery(q: string): string;
83
+ getTable(): string;
35
84
  /**
36
- * @override
85
+ * Ensure the backing table for this repository's model exists.
86
+ * Owns the per-model DDL previously held by PostgresStore.checkTable().
87
+ * @internal Not part of the @webda/models Repository interface.
37
88
  */
38
- _delete(uid: string, writeCondition: any, writeConditionField: string): Promise<void>;
39
- abstract mapExpressionAttribute(attribute: string[]): string;
40
- duplicateExpression(expression: WebdaQL.Expression): WebdaQL.Expression;
89
+ setupTable(): Promise<void>;
41
90
  /**
42
- * @override
91
+ * Run a statement against the client once {@link prepare} has resolved.
92
+ * @param q - the SQL statement
93
+ * @param values - the statement parameters
94
+ * @returns the raw pg query result
43
95
  */
44
- find(query: WebdaQL.Query): Promise<{
45
- results: T[];
46
- continuationToken: string;
47
- filter: WebdaQL.Expression;
96
+ protected execute(q: string, values?: any[]): Promise<{
97
+ rows: any[];
98
+ rowCount: number;
48
99
  }>;
49
100
  /**
50
- * @override
101
+ * Map an expression attribute path array to a JSONB path expression.
102
+ * @param attribute - the attribute path
103
+ * @returns the JSONB path expression
51
104
  */
52
- _exists(uid: string): Promise<boolean>;
105
+ mapExpressionAttribute(attribute: string[]): string;
53
106
  /**
54
- * @override
107
+ * Build a SQL WHERE sub-expression from a write-condition.
108
+ * @param writeCondition - the expected value
109
+ * @param writeConditionField - the field to check
110
+ * @param params - the existing params array (will be extended in place)
111
+ * @returns the SQL AND clause
55
112
  */
56
- _get(uid: string, raiseIfNotFound?: boolean): Promise<T>;
113
+ getQueryCondition(writeCondition: any, writeConditionField: string, params: any[]): string;
57
114
  /**
58
- * @override
115
+ * Run a raw SQL query and return typed results.
116
+ * @param q - the SQL query (WHERE clause or full query)
117
+ * @param values - the query parameters
118
+ * @returns the raw pg query result
59
119
  */
60
- getAll(list?: string[]): Promise<T[]>;
120
+ protected sqlQuery(q: string, values?: any[]): Promise<{
121
+ rows: any[];
122
+ rowCount: number;
123
+ }>;
61
124
  /**
62
- *
63
- * @param itemWriteCondition
64
- * @param itemWriteConditionField
65
- * @param offset parameter offset
125
+ * Deserialize a raw JSON object from the database into a model instance.
126
+ * @param data - the raw JSON object from the JSONB column
127
+ * @returns the model instance
66
128
  */
67
- abstract getQueryCondition(itemWriteCondition: any, itemWriteConditionField: string, values: any[]): any;
129
+ protected fromJSON(data: any): InstanceType<T>;
130
+ /** @override */
131
+ get(primaryKey: any): Promise<any>;
132
+ /** @override */
133
+ create(data: any, _save?: boolean): Promise<any>;
134
+ /** @override */
135
+ update(data: any, conditionField?: any, condition?: any): Promise<void>;
136
+ /** @override */
137
+ patch(primaryKey: any, data: any, conditionField?: any, condition?: any): Promise<void>;
138
+ /** @override */
139
+ delete(primaryKey: any, conditionField?: any, condition?: any): Promise<void>;
140
+ /** @override */
141
+ exists(primaryKey: any): Promise<boolean>;
142
+ /** @override */
143
+ removeAttribute(primaryKey: any, attribute: any, conditionField?: any, condition?: any): Promise<void>;
144
+ /** @override */
145
+ incrementAttributes(primaryKey: any, info: any, _conditionField?: any, _condition?: any): Promise<void>;
146
+ /** @override */
147
+ upsertItemToCollection(primaryKey: any, collection: any, item: any, index?: number, itemWriteConditionField?: any, itemWriteCondition?: any): Promise<void>;
148
+ /** @override */
149
+ deleteItemFromCollection(primaryKey: any, collection: any, index: number, itemWriteConditionField?: any, itemWriteCondition?: any): Promise<void>;
68
150
  /**
69
- * @override
151
+ * Duplicate and translate a WebdaQL expression into SQL-friendly JSONB path expressions.
152
+ * @param expression - the WebdaQL expression
153
+ * @returns the translated expression
70
154
  */
71
- _update(object: any, uid: string, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<any>;
72
- getUuid(object: T | string | ModelLink<T>): string;
155
+ duplicateExpression(expression: WebdaQL.Expression): WebdaQL.Expression;
156
+ /** @override — use SQL WHERE clause instead of in-memory scan */
157
+ query(queryStr: string): Promise<{
158
+ results: InstanceType<T>[];
159
+ continuationToken?: string;
160
+ }>;
161
+ /** @override — iterate via paginated SQL queries */
162
+ iterate(queryStr: string): AsyncGenerator<InstanceType<T>, any, any>;
73
163
  /**
74
- * @override
164
+ * Delete all rows from the table (used in tests).
75
165
  */
76
- _save(object: T): Promise<any>;
77
166
  __clean(): Promise<void>;
78
167
  }
168
+ /** Abstract base class for SQL-backed stores */
169
+ export declare abstract class SQLStore<K extends SQLStoreParameters = SQLStoreParameters> extends Store<K> {
170
+ abstract getRepository<T extends ModelClass>(model: T): Repository<T>;
171
+ }
79
172
  //# sourceMappingURL=sqlstore.d.ts.map
@@ -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