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
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-11 16:05:39 -0400
commit048089ec698fb8237fa0cd5df668f4cfc0b83cab (patch)
treedc21ebff4e7b9c945fade92cf17a1a7d886522a3 /ext/js/data
parenta9f41238d3cda62bc194f6c6cb08bae2c4eb512c (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;
+ }
}