@naturalcycles/datastore-lib 3.25.2 → 3.25.3
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.js +9 -2
- package/package.json +1 -1
- package/src/datastore.db.ts +13 -4
package/dist/datastore.db.js
CHANGED
|
@@ -106,9 +106,11 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
106
106
|
return q.kinds[0];
|
|
107
107
|
}
|
|
108
108
|
async runQuery(dbQuery, _opt) {
|
|
109
|
-
|
|
109
|
+
const idFilter = dbQuery._filters.find(f => f.name === 'id');
|
|
110
|
+
if (idFilter) {
|
|
111
|
+
const ids = idFilter.op === '==' ? [idFilter.val] : idFilter.val;
|
|
110
112
|
return {
|
|
111
|
-
rows: await this.getByIds(dbQuery.table,
|
|
113
|
+
rows: await this.getByIds(dbQuery.table, ids),
|
|
112
114
|
};
|
|
113
115
|
}
|
|
114
116
|
const q = (0, query_util_1.dbQueryToDatastoreQuery)(dbQuery, this.ds().createQuery(dbQuery.table));
|
|
@@ -180,6 +182,11 @@ class DatastoreDB extends db_lib_1.BaseCommonDB {
|
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
async deleteByQuery(q, opt) {
|
|
185
|
+
const idFilter = q._filters.find(f => f.name === 'id');
|
|
186
|
+
if (idFilter) {
|
|
187
|
+
const ids = idFilter.op === '==' ? [idFilter.val] : idFilter.val;
|
|
188
|
+
return await this.deleteByIds(q.table, ids, opt);
|
|
189
|
+
}
|
|
183
190
|
const datastoreQuery = (0, query_util_1.dbQueryToDatastoreQuery)(q.select([]), this.ds().createQuery(q.table));
|
|
184
191
|
const { rows } = await this.runDatastoreQuery(datastoreQuery);
|
|
185
192
|
return await this.deleteByIds(q.table, rows.map(obj => obj.id), opt);
|
package/package.json
CHANGED
package/src/datastore.db.ts
CHANGED
|
@@ -118,7 +118,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
118
118
|
await this.getAllStats()
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
async getByIds<ROW extends ObjectWithId>(
|
|
122
122
|
table: string,
|
|
123
123
|
ids: ROW['id'][],
|
|
124
124
|
_opt?: DatastoreDBOptions,
|
|
@@ -176,9 +176,12 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
176
176
|
dbQuery: DBQuery<ROW>,
|
|
177
177
|
_opt?: DatastoreDBOptions,
|
|
178
178
|
): Promise<RunQueryResult<ROW>> {
|
|
179
|
-
|
|
179
|
+
const idFilter = dbQuery._filters.find(f => f.name === 'id')
|
|
180
|
+
if (idFilter) {
|
|
181
|
+
const ids: string[] = idFilter.op === '==' ? [idFilter.val] : idFilter.val
|
|
182
|
+
|
|
180
183
|
return {
|
|
181
|
-
rows: await this.getByIds(dbQuery.table,
|
|
184
|
+
rows: await this.getByIds(dbQuery.table, ids),
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
|
|
@@ -295,6 +298,12 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
295
298
|
q: DBQuery<ROW>,
|
|
296
299
|
opt?: DatastoreDBOptions,
|
|
297
300
|
): Promise<number> {
|
|
301
|
+
const idFilter = q._filters.find(f => f.name === 'id')
|
|
302
|
+
if (idFilter) {
|
|
303
|
+
const ids: string[] = idFilter.op === '==' ? [idFilter.val] : idFilter.val
|
|
304
|
+
return await this.deleteByIds(q.table, ids, opt)
|
|
305
|
+
}
|
|
306
|
+
|
|
298
307
|
const datastoreQuery = dbQueryToDatastoreQuery(q.select([]), this.ds().createQuery(q.table))
|
|
299
308
|
const { rows } = await this.runDatastoreQuery<ROW>(datastoreQuery)
|
|
300
309
|
return await this.deleteByIds(
|
|
@@ -308,7 +317,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
|
|
|
308
317
|
* Limitation: Datastore's delete returns void, so we always return all ids here as "deleted"
|
|
309
318
|
* regardless if they were actually deleted or not.
|
|
310
319
|
*/
|
|
311
|
-
|
|
320
|
+
async deleteByIds<ROW extends ObjectWithId>(
|
|
312
321
|
table: string,
|
|
313
322
|
ids: ROW['id'][],
|
|
314
323
|
opt: DatastoreDBOptions = {},
|