Fixes for Edge

This commit is contained in:
toasted-nutbread 2019-11-09 20:48:30 -05:00
parent 75883ed885
commit aa92855b37

View File

@ -27,6 +27,7 @@ class Database {
throw new Error('Database already initialized');
}
try {
this.db = await Database.open('dict', 4, (db, transaction, oldVersion) => {
Database.upgrade(db, transaction, oldVersion, [
{
@ -78,6 +79,11 @@ class Database {
}
]);
});
return true;
} catch (e) {
console.error(e);
return false;
}
}
async purge() {
@ -786,14 +792,15 @@ class Database {
for (const objectStoreName of objectStoreNames) {
const {primaryKey, indices} = stores[objectStoreName];
const objectStoreNames = transaction.objectStoreNames || db.objectStoreNames;
const objectStore = (
transaction.objectStoreNames.contains(objectStoreName) ?
Database.listContains(objectStoreNames, objectStoreName) ?
transaction.objectStore(objectStoreName) :
db.createObjectStore(objectStoreName, primaryKey)
);
for (const indexName of indices) {
if (objectStore.indexNames.contains(indexName)) { continue; }
if (Database.listContains(objectStore.indexNames, indexName)) { continue; }
objectStore.createIndex(indexName, indexName, {});
}
@ -808,4 +815,11 @@ class Database {
request.onsuccess = () => resolve();
});
}
static listContains(list, value) {
for (let i = 0, ii = list.length; i < ii; ++i) {
if (list[i] === value) { return true; }
}
return false;
}
}