@naturalcycles/datastore-lib 4.0.0 → 4.0.2
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/datastore.db.d.ts +2 -0
- package/dist/datastore.db.js +13 -1
- package/package.json +1 -1
- package/src/datastore.db.ts +17 -1
package/dist/datastore.db.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
39
39
|
* regardless if they were actually deleted or not.
|
|
40
40
|
*/
|
|
41
41
|
deleteByIds(table: string, ids: string[], opt?: DatastoreDBOptions): Promise<number>;
|
|
42
|
+
createTransaction(opt?: CommonDBTransactionOptions): Promise<DatastoreDBTransaction>;
|
|
42
43
|
runInTransaction(fn: DBTransactionFn, opt?: CommonDBTransactionOptions): Promise<void>;
|
|
43
44
|
getAllStats(): Promise<DatastoreStats[]>;
|
|
44
45
|
/**
|
|
@@ -70,6 +71,7 @@ export declare class DatastoreDBTransaction implements DBTransaction {
|
|
|
70
71
|
db: DatastoreDB;
|
|
71
72
|
tx: Transaction;
|
|
72
73
|
constructor(db: DatastoreDB, tx: Transaction);
|
|
74
|
+
commit(): Promise<void>;
|
|
73
75
|
rollback(): Promise<void>;
|
|
74
76
|
getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBReadOptions): Promise<ROW[]>;
|
|
75
77
|
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
|
package/dist/datastore.db.js
CHANGED
|
@@ -74,7 +74,7 @@ export class DatastoreDB extends BaseCommonDB {
|
|
|
74
74
|
}
|
|
75
75
|
async getDatastoreLib() {
|
|
76
76
|
// Lazy-loading
|
|
77
|
-
const
|
|
77
|
+
const lib = await import('@google-cloud/datastore');
|
|
78
78
|
return lib;
|
|
79
79
|
}
|
|
80
80
|
async ping() {
|
|
@@ -254,6 +254,15 @@ export class DatastoreDB extends BaseCommonDB {
|
|
|
254
254
|
});
|
|
255
255
|
return ids.length;
|
|
256
256
|
}
|
|
257
|
+
async createTransaction(opt = {}) {
|
|
258
|
+
const ds = await this.ds();
|
|
259
|
+
const { readOnly } = opt;
|
|
260
|
+
const datastoreTx = ds.transaction({
|
|
261
|
+
readOnly,
|
|
262
|
+
});
|
|
263
|
+
await datastoreTx.run();
|
|
264
|
+
return new DatastoreDBTransaction(this, datastoreTx);
|
|
265
|
+
}
|
|
257
266
|
async runInTransaction(fn, opt = {}) {
|
|
258
267
|
const ds = await this.ds();
|
|
259
268
|
const { readOnly } = opt;
|
|
@@ -460,6 +469,9 @@ export class DatastoreDBTransaction {
|
|
|
460
469
|
this.db = db;
|
|
461
470
|
this.tx = tx;
|
|
462
471
|
}
|
|
472
|
+
async commit() {
|
|
473
|
+
await this.tx.commit();
|
|
474
|
+
}
|
|
463
475
|
async rollback() {
|
|
464
476
|
try {
|
|
465
477
|
await this.tx.rollback();
|
package/package.json
CHANGED
package/src/datastore.db.ts
CHANGED
|
@@ -142,7 +142,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
142
142
|
|
|
143
143
|
private async getDatastoreLib(): Promise<any> {
|
|
144
144
|
// Lazy-loading
|
|
145
|
-
const
|
|
145
|
+
const lib = await import('@google-cloud/datastore')
|
|
146
146
|
return lib
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -427,6 +427,18 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
427
427
|
return ids.length
|
|
428
428
|
}
|
|
429
429
|
|
|
430
|
+
override async createTransaction(
|
|
431
|
+
opt: CommonDBTransactionOptions = {},
|
|
432
|
+
): Promise<DatastoreDBTransaction> {
|
|
433
|
+
const ds = await this.ds()
|
|
434
|
+
const { readOnly } = opt
|
|
435
|
+
const datastoreTx = ds.transaction({
|
|
436
|
+
readOnly,
|
|
437
|
+
})
|
|
438
|
+
await datastoreTx.run()
|
|
439
|
+
return new DatastoreDBTransaction(this, datastoreTx)
|
|
440
|
+
}
|
|
441
|
+
|
|
430
442
|
override async runInTransaction(
|
|
431
443
|
fn: DBTransactionFn,
|
|
432
444
|
opt: CommonDBTransactionOptions = {},
|
|
@@ -658,6 +670,10 @@ export class DatastoreDBTransaction implements DBTransaction {
|
|
|
658
670
|
public tx: Transaction,
|
|
659
671
|
) {}
|
|
660
672
|
|
|
673
|
+
async commit(): Promise<void> {
|
|
674
|
+
await this.tx.commit()
|
|
675
|
+
}
|
|
676
|
+
|
|
661
677
|
async rollback(): Promise<void> {
|
|
662
678
|
try {
|
|
663
679
|
await this.tx.rollback()
|