@naturalcycles/datastore-lib 3.25.2 → 3.25.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.
@@ -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
- if (dbQuery._ids?.length) {
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, dbQuery._ids),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/datastore-lib",
3
- "version": "3.25.2",
3
+ "version": "3.25.4",
4
4
  "description": "Opinionated library to work with Google Datastore",
5
5
  "scripts": {
6
6
  "prepare": "husky install"
@@ -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
- if (dbQuery._ids?.length) {
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, dbQuery._ids),
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
- override async deleteByIds<ROW extends ObjectWithId>(
320
+ async deleteByIds<ROW extends ObjectWithId>(
312
321
  table: string,
313
322
  ids: ROW['id'][],
314
323
  opt: DatastoreDBOptions = {},