aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data/database.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-14 22:51:20 -0400
committerGitHub <noreply@github.com>2021-03-14 22:51:20 -0400
commita52d86a39e9cca620823e3d97d7c129a7abafced (patch)
tree1e75aef621f21a96a21bdff14ad2e48056ec56d2 /ext/js/data/database.js
parent07df1e011794f5a77f7fb7da5cd9ea353a8747e2 (diff)
Dictionary database improvements (#1527)
* Update formatting * Add _findMultiBulk * Update implementation of findTermsBySequenceBulk * Update tests * Generalize query creation * Remove _findGenericBulk * Reduce function creation * Add more bindings * Simplify findTermsExactBulk implementation * Update var names * Update _findMultiBulk to support multiple index queries * Update findTermsBulk * Update getMedia implementation * Pass data arg to getAll and findFirst to avoid having multiple closures
Diffstat (limited to 'ext/js/data/database.js')
-rw-r--r--ext/js/data/database.js28
1 files changed, 14 insertions, 14 deletions
diff --git a/ext/js/data/database.js b/ext/js/data/database.js
index f44ea1d9..a0a1804a 100644
--- a/ext/js/data/database.js
+++ b/ext/js/data/database.js
@@ -95,11 +95,11 @@ class Database {
});
}
- getAll(objectStoreOrIndex, query, resolve, reject) {
+ getAll(objectStoreOrIndex, query, resolve, reject, data) {
if (typeof objectStoreOrIndex.getAll === 'function') {
- this._getAllFast(objectStoreOrIndex, query, resolve, reject);
+ this._getAllFast(objectStoreOrIndex, query, resolve, reject, data);
} else {
- this._getAllUsingCursor(objectStoreOrIndex, query, resolve, reject);
+ this._getAllUsingCursor(objectStoreOrIndex, query, resolve, reject, data);
}
}
@@ -116,25 +116,25 @@ class Database {
const transaction = this.transaction([objectStoreName], 'readonly');
const objectStore = transaction.objectStore(objectStoreName);
const objectStoreOrIndex = indexName !== null ? objectStore.index(indexName) : objectStore;
- this.findFirst(objectStoreOrIndex, query, resolve, reject, predicate, predicateArg, defaultValue);
+ this.findFirst(objectStoreOrIndex, query, resolve, reject, null, predicate, predicateArg, defaultValue);
});
}
- findFirst(objectStoreOrIndex, query, resolve, reject, predicate, predicateArg, defaultValue) {
+ findFirst(objectStoreOrIndex, query, resolve, reject, data, predicate, predicateArg, defaultValue) {
const noPredicate = (typeof predicate !== 'function');
const request = objectStoreOrIndex.openCursor(query, 'next');
- request.onerror = (e) => reject(e.target.error);
+ request.onerror = (e) => reject(e.target.error, data);
request.onsuccess = (e) => {
const cursor = e.target.result;
if (cursor) {
const {value} = cursor;
if (noPredicate || predicate(value, predicateArg)) {
- resolve(value);
+ resolve(value, data);
} else {
cursor.continue();
}
} else {
- resolve(defaultValue);
+ resolve(defaultValue, data);
}
};
}
@@ -256,23 +256,23 @@ class Database {
return false;
}
- _getAllFast(objectStoreOrIndex, query, resolve, reject) {
+ _getAllFast(objectStoreOrIndex, query, resolve, reject, data) {
const request = objectStoreOrIndex.getAll(query);
- request.onerror = (e) => reject(e.target.error);
- request.onsuccess = (e) => resolve(e.target.result);
+ request.onerror = (e) => reject(e.target.error, data);
+ request.onsuccess = (e) => resolve(e.target.result, data);
}
- _getAllUsingCursor(objectStoreOrIndex, query, resolve, reject) {
+ _getAllUsingCursor(objectStoreOrIndex, query, resolve, reject, data) {
const results = [];
const request = objectStoreOrIndex.openCursor(query, 'next');
- request.onerror = (e) => reject(e.target.error);
+ request.onerror = (e) => reject(e.target.error, data);
request.onsuccess = (e) => {
const cursor = e.target.result;
if (cursor) {
results.push(cursor.value);
cursor.continue();
} else {
- resolve(results);
+ resolve(results, data);
}
};
}