aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-05 20:00:08 -0400
committerGitHub <noreply@github.com>2021-09-05 20:00:08 -0400
commit97a80276f6ce5834ab1b9ad12309df4f6f2f3ec5 (patch)
tree28aa37aa95832cd51d55011ded62dfdbb649703e /ext/js/data
parentf68ad1f843607d4ba1ad216fe16305c420cee8d6 (diff)
Database readwrite transaction updates (#1932)
* Add _readWriteTransaction helper * Improve deleteDictionary order * Make onProgress event optional * Simplify progress rate parameter
Diffstat (limited to 'ext/js/data')
-rw-r--r--ext/js/data/database.js21
1 files changed, 11 insertions, 10 deletions
diff --git a/ext/js/data/database.js b/ext/js/data/database.js
index 224233a8..cc4f39f9 100644
--- a/ext/js/data/database.js
+++ b/ext/js/data/database.js
@@ -76,9 +76,7 @@ class Database {
return;
}
- const transaction = this.transaction([objectStoreName], 'readwrite');
- transaction.onerror = (e) => reject(e.target.error);
- transaction.oncomplete = () => resolve();
+ const transaction = this._readWriteTransaction([objectStoreName], resolve, reject);
const objectStore = transaction.objectStore(objectStoreName);
for (let i = start, ii = start + count; i < ii; ++i) {
objectStore.add(items[i]);
@@ -161,9 +159,7 @@ class Database {
delete(objectStoreName, key) {
return new Promise((resolve, reject) => {
- const transaction = this.transaction([objectStoreName], 'readwrite');
- transaction.onerror = (e) => reject(e.target.error);
- transaction.oncomplete = () => resolve();
+ const transaction = this._readWriteTransaction([objectStoreName], resolve, reject);
const objectStore = transaction.objectStore(objectStoreName);
objectStore.delete(key);
transaction.commit();
@@ -172,10 +168,7 @@ class Database {
bulkDelete(objectStoreName, indexName, query, filterKeys=null, onProgress=null) {
return new Promise((resolve, reject) => {
- const transaction = this.transaction([objectStoreName], 'readwrite');
- transaction.onerror = (e) => reject(e.target.error);
- transaction.oncomplete = () => resolve();
-
+ const transaction = this._readWriteTransaction([objectStoreName], resolve, reject);
const objectStore = transaction.objectStore(objectStoreName);
const objectStoreOrIndex = indexName !== null ? objectStore.index(indexName) : objectStore;
@@ -317,4 +310,12 @@ class Database {
}
}
}
+
+ _readWriteTransaction(storeNames, resolve, reject) {
+ const transaction = this.transaction(storeNames, 'readwrite');
+ transaction.onerror = (e) => reject(e.target.error);
+ transaction.onabort = () => reject(new Error('Transaction aborted'));
+ transaction.oncomplete = () => resolve();
+ return transaction;
+ }
}