From 1a8bbf32d580173f5997754f6b36015ae212c9f9 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 30 Mar 2020 20:27:37 -0400 Subject: Make dictionaryExists public --- ext/bg/js/database.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ext') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 5109e9e8..effa50a6 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -322,6 +322,15 @@ class Database { return result; } + async dictionaryExists(title) { + this._validate(); + const transaction = this.db.transaction(['dictionaries'], 'readonly'); + const index = transaction.objectStore('dictionaries').index('title'); + const query = IDBKeyRange.only(title); + const count = await Database._getCount(index, query); + return count > 0; + } + bulkAdd(objectStoreName, items, start, count) { return new Promise((resolve, reject) => { const transaction = this.db.transaction([objectStoreName], 'readwrite'); @@ -380,7 +389,7 @@ class Database { } // Verify database is not already imported - if (await this._dictionaryExists(dictionaryTitle)) { + if (await this.dictionaryExists(dictionaryTitle)) { throw new Error('Dictionary is already imported'); } @@ -592,15 +601,6 @@ class Database { return [termBank, termMetaBank, kanjiBank, kanjiMetaBank, tagBank]; } - async _dictionaryExists(title) { - const db = this.db; - const dbCountTransaction = db.transaction(['dictionaries'], 'readonly'); - const dbIndex = dbCountTransaction.objectStore('dictionaries').index('title'); - const only = IDBKeyRange.only(title); - const count = await Database._getCount(dbIndex, only); - return count > 0; - } - async _findGenericBulk(tableName, indexName, indexValueList, dictionaries, createResult) { this._validate(); -- cgit v1.2.3