@bbn/bbn 2.0.231 → 2.0.233

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.
package/dist/db.d.ts CHANGED
@@ -27,9 +27,30 @@ interface IDbApi {
27
27
  copyTable(target: string, table: string, fields?: string[], where?: unknown, order?: OrderClause, start?: number, limit?: number | null): Promise<number>;
28
28
  deleteTable(table: string): Promise<boolean>;
29
29
  }
30
+ declare class DbObject implements IDbApi {
31
+ private readonly dbName;
32
+ private lastErr;
33
+ constructor(dbName: string);
34
+ private hasMissingStores;
35
+ private getConnection;
36
+ private get structure();
37
+ private getStore;
38
+ lastError(): unknown;
39
+ close(): void;
40
+ insert(table: string, data: Record<string, unknown> | Record<string, unknown>[]): Promise<number>;
41
+ update(table: string, data: Record<string, unknown>, where: WhereObject, replace?: boolean): Promise<number>;
42
+ delete(table: string, where: Record<string, unknown>): Promise<number>;
43
+ selectOne(table: string, field: string, where?: unknown, order?: OrderClause, start?: number, limit?: number): Promise<unknown>;
44
+ select(table: string, fields?: string[], where?: unknown, order?: OrderClause, start?: number): Promise<Record<string, unknown> | null>;
45
+ selectAll(table: string, fields?: string[], where?: unknown, order?: OrderClause, start?: number, limit?: number | null): Promise<Record<string, unknown>[]>;
46
+ getColumnValues(table: string, field: string, where?: unknown, order?: OrderClause, start?: number, limit?: number | null): Promise<unknown[]>;
47
+ copyTable(target: string, table: string, fields?: string[], where?: unknown, order?: OrderClause, start?: number, limit?: number | null): Promise<number>;
48
+ deleteTable(table: string): Promise<boolean>;
49
+ }
30
50
  interface DbManager {
31
51
  _structures: DbStructures;
32
52
  _connections: Record<string, IDBDatabase>;
53
+ _objects: Record<string, DbObject>;
33
54
  _stores: Record<string, unknown>;
34
55
  ok: boolean;
35
56
  open(name: string, version?: number): Promise<IDbApi>;
package/dist/db.js CHANGED
@@ -308,6 +308,7 @@ class DbObject {
308
308
  }
309
309
  let connection = yield this.getConnection();
310
310
  if (!connection.objectStoreNames.contains(target)) {
311
+ connection.close();
311
312
  yield db.add(this.dbName, target, this.structure[table]);
312
313
  connection = yield this.getConnection();
313
314
  }
@@ -318,7 +319,9 @@ class DbObject {
318
319
  if (!rows.length) {
319
320
  return 0;
320
321
  }
321
- return this.insert(target, rows);
322
+ const res = yield this.insert(target, rows);
323
+ connection.close();
324
+ return res;
322
325
  });
323
326
  }
324
327
  deleteTable(table) {
@@ -331,6 +334,7 @@ class DbObject {
331
334
  const db = {
332
335
  _structures: {},
333
336
  _connections: {},
337
+ _objects: {},
334
338
  _stores: {},
335
339
  ok: idb !== undefined,
336
340
  close(database) {
@@ -338,6 +342,7 @@ const db = {
338
342
  if (conn) {
339
343
  conn.close();
340
344
  delete this._connections[database];
345
+ delete this._objects[database];
341
346
  }
342
347
  },
343
348
  updateStructure(storeName, structure, database) {
@@ -419,8 +424,8 @@ const db = {
419
424
  if (!this._structures[database]) {
420
425
  throw new Error(_('Impossible to find a structure for the database %s', database));
421
426
  }
422
- if (this._connections[database]) {
423
- return new DbObject(database);
427
+ if (this._objects[database]) {
428
+ return this._objects[database];
424
429
  }
425
430
  yield new Promise((resolve, reject) => {
426
431
  const req = version ? idb.open(database, version) : idb.open(database);
@@ -442,7 +447,8 @@ const db = {
442
447
  reject(_('open: Upgrade blocked for database %s. Please close other connections to proceed.', database));
443
448
  };
444
449
  });
445
- return new DbObject(database);
450
+ this._objects[database] = new DbObject(database);
451
+ return this._objects[database];
446
452
  });
447
453
  },
448
454
  add(database, name, structure) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.231",
3
+ "version": "2.0.233",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",