From 3122fb60ce5c8acd8cb09974bc2718d96612456d Mon Sep 17 00:00:00 2001 From: kirillgroshkov Date: Sat, 3 Dec 2022 01:04:19 +0100 Subject: [PATCH] fix: adapt to db-lib without CommonDB.getByIds --- src/datastore.db.ts | 17 +++++++++++++---- yarn.lock | 18 +++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/datastore.db.ts b/src/datastore.db.ts index eae3a57..376e7f8 100644 --- a/src/datastore.db.ts +++ b/src/datastore.db.ts @@ -118,7 +118,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { await this.getAllStats() } - override async getByIds( + async getByIds( table: string, ids: ROW['id'][], _opt?: DatastoreDBOptions, @@ -176,9 +176,12 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { dbQuery: DBQuery, _opt?: DatastoreDBOptions, ): Promise> { - if (dbQuery._ids?.length) { + const idFilter = dbQuery._filters.find(f => f.name === 'id') + if (idFilter) { + const ids: string[] = idFilter.op === '==' ? [idFilter.val] : idFilter.val + return { - rows: await this.getByIds(dbQuery.table, dbQuery._ids), + rows: await this.getByIds(dbQuery.table, ids), } } @@ -295,6 +298,12 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { q: DBQuery, opt?: DatastoreDBOptions, ): Promise { + const idFilter = q._filters.find(f => f.name === 'id') + if (idFilter) { + const ids: string[] = idFilter.op === '==' ? [idFilter.val] : idFilter.val + return await this.deleteByIds(q.table, ids, opt) + } + const datastoreQuery = dbQueryToDatastoreQuery(q.select([]), this.ds().createQuery(q.table)) const { rows } = await this.runDatastoreQuery(datastoreQuery) return await this.deleteByIds( @@ -308,7 +317,7 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB { * Limitation: Datastore's delete returns void, so we always return all ids here as "deleted" * regardless if they were actually deleted or not. */ - override async deleteByIds( + async deleteByIds( table: string, ids: ROW['id'][], opt: DatastoreDBOptions = {}, diff --git a/yarn.lock b/yarn.lock index 46e3382..3096200 100644 --- a/yarn.lock +++ b/yarn.lock @@ -854,9 +854,9 @@ typescript "^4.0.2" "@naturalcycles/db-lib@^8.46.1": - version "8.47.0" - resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-8.47.0.tgz#dc6d7f3c3aa6d915803074adca72153fe80a9050" - integrity sha512-2ByptyD59MtjcuczofIkb2NpkjgCjUMXEZDEYWDko10Li1UjdFcpoPPOlulF2chhkwoV0VZiaHeDPw3Oyqod9A== + version "8.48.0" + resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-8.48.0.tgz#5034c214204ae8e8e261127c6ccdcaacf9eb6ebd" + integrity sha512-APKvpzz5NZMPmE6hgt+wvqgIzB0aAo+AHI9T0/v75wIq8La0piVYIrju2BDktnaFn+6QR19xa0HVYDRoXlnT+w== dependencies: "@naturalcycles/js-lib" "^14.116.0" "@naturalcycles/nodejs-lib" "^12.0.0" @@ -2572,9 +2572,9 @@ eslint-visitor-keys@^3.3.0: integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA== eslint@^8.0.0: - version "8.28.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.28.0.tgz#81a680732634677cc890134bcdd9fdfea8e63d6e" - integrity sha512-S27Di+EVyMxcHiwDrFzk8dJYAaD+/5SoWKxL1ri/71CRHsnJnRDPNt2Kzj24+MT9FDupf4aqqyqPrvI8MvQ4VQ== + version "8.29.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.29.0.tgz#d74a88a20fb44d59c51851625bc4ee8d0ec43f87" + integrity sha512-isQ4EEiyUjZFbEKvEGJKKGBwXtvXX+zJbkVKCgTuB9t/+jUBcy8avhkEwWJecI15BkRkOYmvIM5ynbhRjEkoeg== dependencies: "@eslint/eslintrc" "^1.3.3" "@humanwhocodes/config-array" "^0.11.6" @@ -2769,9 +2769,9 @@ fastest-levenshtein@^1.0.16: integrity sha512-eRnCtTTtGZFpQCwhJiUOuxPQWRXVKYDn0b2PeHfXL6/Zi53SLAzAHfVhVWK2AryC/WH05kGfxhFIPvTF0SXQzg== fastq@^1.6.0: - version "1.13.0" - resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.13.0.tgz#616760f88a7526bdfc596b7cab8c18938c36b98c" - integrity sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw== + version "1.14.0" + resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.14.0.tgz#107f69d7295b11e0fccc264e1fc6389f623731ce" + integrity sha512-eR2D+V9/ExcbF9ls441yIuN6TI2ED1Y2ZcA5BmMtJsOkWOFRJQ0Jt0g1UwqXJJVAb+V+umH5Dfr8oh4EVP7VVg== dependencies: reusify "^1.0.4"