From 1cddd4094afb9a4b1a7f3f8e7b90b55ef5bf36b0 Mon Sep 17 00:00:00 2001 From: Jytesh <44925963+Jytesh@users.noreply.github.com> Date: Tue, 25 May 2021 17:54:07 +0530 Subject: [PATCH] Feat: Allow empty namespaces in stores redis has not been updated Signed-off-by: Jytesh <44925963+Jytesh@users.noreply.github.com> --- packages/keyv-mongo/src/index.js | 4 ++-- packages/keyv-sql/src/index.js | 4 ++-- packages/keyv/src/index.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/keyv-mongo/src/index.js b/packages/keyv-mongo/src/index.js index 005111b..a2faf95 100644 --- a/packages/keyv-mongo/src/index.js +++ b/packages/keyv-mongo/src/index.js @@ -96,13 +96,13 @@ class KeyvMongo extends EventEmitter { clear() { return this.connect - .then(store => store.deleteMany({ key: new RegExp(`^${this.namespace}:`) }) + .then(store => store.deleteMany({ key: new RegExp(`^${this.namespace}`) }) .then(() => undefined)); } async * iterator() { const iterator = await this.connect - .then(store => store.find({ key: new RegExp(`^${this.namespace}:`) }).map(x => { + .then(store => store.find({ key: new RegExp(`^${this.namespace}`) }).map(x => { return [x.key, x.value]; })); yield * iterator; diff --git a/packages/keyv-sql/src/index.js b/packages/keyv-sql/src/index.js index da5c209..373ad80 100644 --- a/packages/keyv-sql/src/index.js +++ b/packages/keyv-sql/src/index.js @@ -65,14 +65,14 @@ class KeyvSql extends EventEmitter { } clear() { - const del = this.options.dialect === 'mysql' ? `DELETE FROM \`${this.options.table}\` WHERE (\`${this.options.table}\`.\`key\` LIKE '${this.namespace}:%')` : `DELETE FROM "${this.options.table}" WHERE ("${this.options.table}"."key" LIKE '${this.namespace}:%')`; + const del = this.options.dialect === 'mysql' ? `DELETE FROM \`${this.options.table}\` WHERE (\`${this.options.table}\`.\`key\` LIKE '${this.namespace}%')` : `DELETE FROM "${this.options.table}" WHERE ("${this.options.table}"."key" LIKE '${this.namespace}%')`; return this.query(del) .then(() => undefined); } async * iterator() { const limit = Number.parseInt(this.options.iterationLimit, 10); - const selectChunk = this.options.dialect === 'mysql' ? `SELECT * FROM \`${this.options.table}\` WHERE (\`${this.options.table}\`.\`key\` LIKE '${this.namespace}:%') LIMIT ${limit} OFFSET ` : `SELECT * FROM "${this.options.table}" WHERE ("${this.options.table}"."key" LIKE '${this.namespace}:%') LIMIT ${limit} OFFSET `; + const selectChunk = this.options.dialect === 'mysql' ? `SELECT * FROM \`${this.options.table}\` WHERE (\`${this.options.table}\`.\`key\` LIKE '${this.namespace}%') LIMIT ${limit} OFFSET ` : `SELECT * FROM "${this.options.table}" WHERE ("${this.options.table}"."key" LIKE '${this.namespace}%') LIMIT ${limit} OFFSET `; async function * iterate(offset, query) { const entries = await query(selectChunk + offset); diff --git a/packages/keyv/src/index.js b/packages/keyv/src/index.js index 656dfdc..b717825 100644 --- a/packages/keyv/src/index.js +++ b/packages/keyv/src/index.js @@ -25,7 +25,7 @@ class Keyv extends EventEmitter { this.store.on('error', error => this.emit('error', error)); } - this.store.namespace = this.options.namespace; + this.store.namespace = this.options.namespace ? this.options.namespace + ':' : ''; const generateIterator = iterator => async function * () { for await (const [key, raw] of (typeof iterator === 'function' ? iterator() : iterator)) {