aboutsummaryrefslogtreecommitdiff
path: root/ext/js/data/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/data/database.js')
-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;
+ }
}