Fixes for Edge
This commit is contained in:
parent
75883ed885
commit
aa92855b37
@ -27,6 +27,7 @@ class Database {
|
|||||||
throw new Error('Database already initialized');
|
throw new Error('Database already initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
this.db = await Database.open('dict', 4, (db, transaction, oldVersion) => {
|
this.db = await Database.open('dict', 4, (db, transaction, oldVersion) => {
|
||||||
Database.upgrade(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() {
|
async purge() {
|
||||||
@ -786,14 +792,15 @@ class Database {
|
|||||||
for (const objectStoreName of objectStoreNames) {
|
for (const objectStoreName of objectStoreNames) {
|
||||||
const {primaryKey, indices} = stores[objectStoreName];
|
const {primaryKey, indices} = stores[objectStoreName];
|
||||||
|
|
||||||
|
const objectStoreNames = transaction.objectStoreNames || db.objectStoreNames;
|
||||||
const objectStore = (
|
const objectStore = (
|
||||||
transaction.objectStoreNames.contains(objectStoreName) ?
|
Database.listContains(objectStoreNames, objectStoreName) ?
|
||||||
transaction.objectStore(objectStoreName) :
|
transaction.objectStore(objectStoreName) :
|
||||||
db.createObjectStore(objectStoreName, primaryKey)
|
db.createObjectStore(objectStoreName, primaryKey)
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const indexName of indices) {
|
for (const indexName of indices) {
|
||||||
if (objectStore.indexNames.contains(indexName)) { continue; }
|
if (Database.listContains(objectStore.indexNames, indexName)) { continue; }
|
||||||
|
|
||||||
objectStore.createIndex(indexName, indexName, {});
|
objectStore.createIndex(indexName, indexName, {});
|
||||||
}
|
}
|
||||||
@ -808,4 +815,11 @@ class Database {
|
|||||||
request.onsuccess = () => resolve();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user