Make dictionaryExists public

This commit is contained in:
toasted-nutbread 2020-03-30 20:27:37 -04:00
parent a6fedae9c7
commit 1a8bbf32d5

View File

@ -322,6 +322,15 @@ class Database {
return result; 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) { bulkAdd(objectStoreName, items, start, count) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const transaction = this.db.transaction([objectStoreName], 'readwrite'); const transaction = this.db.transaction([objectStoreName], 'readwrite');
@ -380,7 +389,7 @@ class Database {
} }
// Verify database is not already imported // Verify database is not already imported
if (await this._dictionaryExists(dictionaryTitle)) { if (await this.dictionaryExists(dictionaryTitle)) {
throw new Error('Dictionary is already imported'); throw new Error('Dictionary is already imported');
} }
@ -592,15 +601,6 @@ class Database {
return [termBank, termMetaBank, kanjiBank, kanjiMetaBank, tagBank]; 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) { async _findGenericBulk(tableName, indexName, indexValueList, dictionaries, createResult) {
this._validate(); this._validate();