@quatrain/backend-sqlite 1.1.6 → 1.1.7

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.
@@ -2,7 +2,9 @@ import { DataObjectClass, AbstractBackendAdapter, BackendParameters, QueryResult
2
2
  import sqlite3 from 'sqlite3';
3
3
  import { Database } from 'sqlite';
4
4
  /**
5
- * SQLite Backend Adapter for Quatrain
5
+ * Backend adapter implementation for SQLite databases.
6
+ * Uses the `sqlite` driver to provide a fast, local relational store without external dependencies.
7
+ * Highly useful for local development, CI/CD testing environments, or lightweight local deployments.
6
8
  */
7
9
  export declare class SQLiteAdapter extends AbstractBackendAdapter {
8
10
  protected _connection: undefined | Database<sqlite3.Database>;
@@ -10,8 +12,11 @@ export declare class SQLiteAdapter extends AbstractBackendAdapter {
10
12
  constructor(params?: BackendParameters);
11
13
  protected _buildPath(dataObject: DataObjectClass<any>, uid?: string): string;
12
14
  /**
13
- * Executes a raw query on the backend.
14
- * Only supported by SQL adapters.
15
+ * Executes an arbitrary raw SQL query against the SQLite database.
16
+ *
17
+ * @param sql - The SQL statement with optional `?` parameterized placeholders.
18
+ * @param params - The array of parameter values.
19
+ * @returns A promise resolving to the SQLite result rows.
15
20
  */
16
21
  rawQuery(sql: string, params?: any[]): Promise<any>;
17
22
  protected _connect(): Promise<Database<sqlite3.Database>>;
@@ -28,15 +33,44 @@ export declare class SQLiteAdapter extends AbstractBackendAdapter {
28
33
  */
29
34
  private _ensureTable;
30
35
  /**
31
- * Create record in backend
32
- * @param dataObject DataObject instance to persist in backend
33
- * @param desiredUid Desired unique ID for record
34
- * @returns DataObject
36
+ * Translates a DataObject creation request into an `INSERT INTO` SQL query.
37
+ * SQLite handles JSON by parsing array properties internally.
38
+ *
39
+ * @param dataObject - The DataObject payload.
40
+ * @param desiredUid - Optional explicit UUID.
41
+ * @returns A promise resolving to the saved DataObject.
35
42
  */
36
43
  create(dataObject: DataObjectClass<any>, desiredUid: string | undefined): Promise<DataObjectClass<any>>;
44
+ /**
45
+ * Executes a `SELECT *` query to retrieve a document by its UID.
46
+ * Handles mapping of JSON text columns back into arrays/objects.
47
+ *
48
+ * @param dataObject - The empty DataObject containing the target path.
49
+ * @returns A promise resolving to the hydrated DataObject.
50
+ */
37
51
  read(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
52
+ /**
53
+ * Processes an `UPDATE` command for modified object properties.
54
+ * Automatically ensures the table exists and properly escapes JSON-backed properties.
55
+ *
56
+ * @param dataObject - The modified DataObject.
57
+ * @returns A promise resolving to the updated instance.
58
+ */
38
59
  update(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>>;
60
+ /**
61
+ * Generates a `DELETE FROM` or `UPDATE` query depending on the `hardDelete` parameter.
62
+ *
63
+ * @param dataObject - The DataObject to remove.
64
+ * @param hardDelete - Force permanent deletion over soft delete.
65
+ * @returns A promise resolving upon completion.
66
+ */
39
67
  delete(dataObject: DataObjectClass<any>, hardDelete?: boolean): Promise<DataObjectClass<any>>;
68
+ /**
69
+ * Wipes all records from a table by executing a blanket `DELETE FROM`.
70
+ *
71
+ * @param collection - The table name to purge.
72
+ * @param batchSize - Ignored for SQLite bulk deletes.
73
+ */
40
74
  deleteCollection(collection: string, batchSize?: number): Promise<void>;
41
75
  /**
42
76
  * Convert array into SQL expression
@@ -45,12 +79,14 @@ export declare class SQLiteAdapter extends AbstractBackendAdapter {
45
79
  */
46
80
  protected _array2String(from: (string | number)[]): string;
47
81
  /**
48
- * Execute a query on a collection
49
- * @param dataObject
50
- * @param filters
51
- * @param pagination
52
- * @params parent
53
- * @returns
82
+ * Translates the Quatrain `Filters` logic into SQLite query syntax.
83
+ * Employs internal `json_each` extensions for Array-contains searches when JSON1 is available.
84
+ *
85
+ * @param dataObject - The targeted collection object.
86
+ * @param filters - Requested Query filters.
87
+ * @param pagination - Query Limits & Pagination rules.
88
+ * @param parent - Optional parent linkage.
89
+ * @returns A promise resolving to hydrated objects and metadata.
54
90
  */
55
91
  find(dataObject: DataObjectClass<any>, filters?: Filters | Filter[] | undefined, pagination?: SortAndLimit | undefined, parent?: DataObjectClass<any> | undefined): Promise<QueryResultType<DataObjectClass<any>>>;
56
92
  /**
@@ -34,7 +34,9 @@ const operatorsMap = {
34
34
  isNotNull: 'IS NOT NULL',
35
35
  };
36
36
  /**
37
- * SQLite Backend Adapter for Quatrain
37
+ * Backend adapter implementation for SQLite databases.
38
+ * Uses the `sqlite` driver to provide a fast, local relational store without external dependencies.
39
+ * Highly useful for local development, CI/CD testing environments, or lightweight local deployments.
38
40
  */
39
41
  class SQLiteAdapter extends backend_1.AbstractBackendAdapter {
40
42
  constructor(params = {}) {
@@ -61,8 +63,11 @@ class SQLiteAdapter extends backend_1.AbstractBackendAdapter {
61
63
  return path;
62
64
  }
63
65
  /**
64
- * Executes a raw query on the backend.
65
- * Only supported by SQL adapters.
66
+ * Executes an arbitrary raw SQL query against the SQLite database.
67
+ *
68
+ * @param sql - The SQL statement with optional `?` parameterized placeholders.
69
+ * @param params - The array of parameter values.
70
+ * @returns A promise resolving to the SQLite result rows.
66
71
  */
67
72
  rawQuery(sql_1) {
68
73
  return __awaiter(this, arguments, void 0, function* (sql, params = []) {
@@ -175,10 +180,12 @@ class SQLiteAdapter extends backend_1.AbstractBackendAdapter {
175
180
  });
176
181
  }
177
182
  /**
178
- * Create record in backend
179
- * @param dataObject DataObject instance to persist in backend
180
- * @param desiredUid Desired unique ID for record
181
- * @returns DataObject
183
+ * Translates a DataObject creation request into an `INSERT INTO` SQL query.
184
+ * SQLite handles JSON by parsing array properties internally.
185
+ *
186
+ * @param dataObject - The DataObject payload.
187
+ * @param desiredUid - Optional explicit UUID.
188
+ * @returns A promise resolving to the saved DataObject.
182
189
  */
183
190
  create(dataObject, desiredUid) {
184
191
  return __awaiter(this, void 0, void 0, function* () {
@@ -239,6 +246,13 @@ class SQLiteAdapter extends backend_1.AbstractBackendAdapter {
239
246
  }
240
247
  });
241
248
  }
249
+ /**
250
+ * Executes a `SELECT *` query to retrieve a document by its UID.
251
+ * Handles mapping of JSON text columns back into arrays/objects.
252
+ *
253
+ * @param dataObject - The empty DataObject containing the target path.
254
+ * @returns A promise resolving to the hydrated DataObject.
255
+ */
242
256
  read(dataObject) {
243
257
  return __awaiter(this, void 0, void 0, function* () {
244
258
  const path = dataObject.path;
@@ -303,6 +317,13 @@ class SQLiteAdapter extends backend_1.AbstractBackendAdapter {
303
317
  return dataObject;
304
318
  });
305
319
  }
320
+ /**
321
+ * Processes an `UPDATE` command for modified object properties.
322
+ * Automatically ensures the table exists and properly escapes JSON-backed properties.
323
+ *
324
+ * @param dataObject - The modified DataObject.
325
+ * @returns A promise resolving to the updated instance.
326
+ */
306
327
  update(dataObject) {
307
328
  return __awaiter(this, void 0, void 0, function* () {
308
329
  if (dataObject.uid === undefined) {
@@ -349,6 +370,13 @@ class SQLiteAdapter extends backend_1.AbstractBackendAdapter {
349
370
  return dataObject;
350
371
  });
351
372
  }
373
+ /**
374
+ * Generates a `DELETE FROM` or `UPDATE` query depending on the `hardDelete` parameter.
375
+ *
376
+ * @param dataObject - The DataObject to remove.
377
+ * @param hardDelete - Force permanent deletion over soft delete.
378
+ * @returns A promise resolving upon completion.
379
+ */
352
380
  delete(dataObject_1) {
353
381
  return __awaiter(this, arguments, void 0, function* (dataObject, hardDelete = false) {
354
382
  if (dataObject.uid === undefined) {
@@ -379,6 +407,12 @@ class SQLiteAdapter extends backend_1.AbstractBackendAdapter {
379
407
  return dataObject;
380
408
  });
381
409
  }
410
+ /**
411
+ * Wipes all records from a table by executing a blanket `DELETE FROM`.
412
+ *
413
+ * @param collection - The table name to purge.
414
+ * @param batchSize - Ignored for SQLite bulk deletes.
415
+ */
382
416
  deleteCollection(collection_1) {
383
417
  return __awaiter(this, arguments, void 0, function* (collection, batchSize = 500) {
384
418
  backend_1.Backend.log(`Deleting all records from collection '${collection}'`);
@@ -400,12 +434,14 @@ class SQLiteAdapter extends backend_1.AbstractBackendAdapter {
400
434
  return `'${JSON.stringify(from)}'`;
401
435
  }
402
436
  /**
403
- * Execute a query on a collection
404
- * @param dataObject
405
- * @param filters
406
- * @param pagination
407
- * @params parent
408
- * @returns
437
+ * Translates the Quatrain `Filters` logic into SQLite query syntax.
438
+ * Employs internal `json_each` extensions for Array-contains searches when JSON1 is available.
439
+ *
440
+ * @param dataObject - The targeted collection object.
441
+ * @param filters - Requested Query filters.
442
+ * @param pagination - Query Limits & Pagination rules.
443
+ * @param parent - Optional parent linkage.
444
+ * @returns A promise resolving to hydrated objects and metadata.
409
445
  */
410
446
  find(dataObject_1) {
411
447
  return __awaiter(this, arguments, void 0, function* (dataObject, filters = undefined, pagination = undefined, parent = undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/backend-sqlite",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "Backend adapter for SQLite",
6
6
  "main": "dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
22
22
  "dependencies": {
23
- "@quatrain/backend": "^1.2.4",
23
+ "@quatrain/backend": "^1.2.7",
24
24
  "@quatrain/core": "^1.2.5",
25
25
  "sqlite": "^5.1.1",
26
26
  "sqlite3": "^5.1.7"
@@ -28,6 +28,7 @@
28
28
  "devDependencies": {
29
29
  "@faker-js/faker": "^7.6.0",
30
30
  "@jest/expect": "^30.0.0",
31
+ "@quatrain/testing": "^1.1.3",
31
32
  "@tsconfig/recommended": "^1.0.1",
32
33
  "@types/jest": "^29.5.12",
33
34
  "@types/node": "^22.10.1",
@@ -40,7 +40,9 @@ const operatorsMap: { [x: string]: string } = {
40
40
  }
41
41
 
42
42
  /**
43
- * SQLite Backend Adapter for Quatrain
43
+ * Backend adapter implementation for SQLite databases.
44
+ * Uses the `sqlite` driver to provide a fast, local relational store without external dependencies.
45
+ * Highly useful for local development, CI/CD testing environments, or lightweight local deployments.
44
46
  */
45
47
  export class SQLiteAdapter extends AbstractBackendAdapter {
46
48
  protected _connection: undefined | Database<sqlite3.Database>
@@ -78,8 +80,11 @@ export class SQLiteAdapter extends AbstractBackendAdapter {
78
80
  }
79
81
 
80
82
  /**
81
- * Executes a raw query on the backend.
82
- * Only supported by SQL adapters.
83
+ * Executes an arbitrary raw SQL query against the SQLite database.
84
+ *
85
+ * @param sql - The SQL statement with optional `?` parameterized placeholders.
86
+ * @param params - The array of parameter values.
87
+ * @returns A promise resolving to the SQLite result rows.
83
88
  */
84
89
  async rawQuery(sql: string, params: any[] = []): Promise<any> {
85
90
  const connection = await this._connect()
@@ -205,10 +210,12 @@ export class SQLiteAdapter extends AbstractBackendAdapter {
205
210
  }
206
211
 
207
212
  /**
208
- * Create record in backend
209
- * @param dataObject DataObject instance to persist in backend
210
- * @param desiredUid Desired unique ID for record
211
- * @returns DataObject
213
+ * Translates a DataObject creation request into an `INSERT INTO` SQL query.
214
+ * SQLite handles JSON by parsing array properties internally.
215
+ *
216
+ * @param dataObject - The DataObject payload.
217
+ * @param desiredUid - Optional explicit UUID.
218
+ * @returns A promise resolving to the saved DataObject.
212
219
  */
213
220
  async create(
214
221
  dataObject: DataObjectClass<any>,
@@ -295,6 +302,13 @@ export class SQLiteAdapter extends AbstractBackendAdapter {
295
302
  }
296
303
  }
297
304
 
305
+ /**
306
+ * Executes a `SELECT *` query to retrieve a document by its UID.
307
+ * Handles mapping of JSON text columns back into arrays/objects.
308
+ *
309
+ * @param dataObject - The empty DataObject containing the target path.
310
+ * @returns A promise resolving to the hydrated DataObject.
311
+ */
298
312
  async read(dataObject: DataObjectClass<any>): Promise<DataObjectClass<any>> {
299
313
  const path = dataObject.path
300
314
  const collection = this.getCollection(dataObject)
@@ -382,6 +396,13 @@ export class SQLiteAdapter extends AbstractBackendAdapter {
382
396
  return dataObject
383
397
  }
384
398
 
399
+ /**
400
+ * Processes an `UPDATE` command for modified object properties.
401
+ * Automatically ensures the table exists and properly escapes JSON-backed properties.
402
+ *
403
+ * @param dataObject - The modified DataObject.
404
+ * @returns A promise resolving to the updated instance.
405
+ */
385
406
  async update(
386
407
  dataObject: DataObjectClass<any>
387
408
  ): Promise<DataObjectClass<any>> {
@@ -450,6 +471,13 @@ export class SQLiteAdapter extends AbstractBackendAdapter {
450
471
  return dataObject
451
472
  }
452
473
 
474
+ /**
475
+ * Generates a `DELETE FROM` or `UPDATE` query depending on the `hardDelete` parameter.
476
+ *
477
+ * @param dataObject - The DataObject to remove.
478
+ * @param hardDelete - Force permanent deletion over soft delete.
479
+ * @returns A promise resolving upon completion.
480
+ */
453
481
  async delete(
454
482
  dataObject: DataObjectClass<any>,
455
483
  hardDelete = false
@@ -491,6 +519,12 @@ export class SQLiteAdapter extends AbstractBackendAdapter {
491
519
  return dataObject
492
520
  }
493
521
 
522
+ /**
523
+ * Wipes all records from a table by executing a blanket `DELETE FROM`.
524
+ *
525
+ * @param collection - The table name to purge.
526
+ * @param batchSize - Ignored for SQLite bulk deletes.
527
+ */
494
528
  async deleteCollection(collection: string, batchSize = 500): Promise<void> {
495
529
  Backend.log(`Deleting all records from collection '${collection}'`)
496
530
  const db = await this._connect()
@@ -517,12 +551,14 @@ export class SQLiteAdapter extends AbstractBackendAdapter {
517
551
  }
518
552
 
519
553
  /**
520
- * Execute a query on a collection
521
- * @param dataObject
522
- * @param filters
523
- * @param pagination
524
- * @params parent
525
- * @returns
554
+ * Translates the Quatrain `Filters` logic into SQLite query syntax.
555
+ * Employs internal `json_each` extensions for Array-contains searches when JSON1 is available.
556
+ *
557
+ * @param dataObject - The targeted collection object.
558
+ * @param filters - Requested Query filters.
559
+ * @param pagination - Query Limits & Pagination rules.
560
+ * @param parent - Optional parent linkage.
561
+ * @returns A promise resolving to hydrated objects and metadata.
526
562
  */
527
563
  async find(
528
564
  dataObject: DataObjectClass<any>,