Last active
October 4, 2018 14:59
-
-
Save bwindels/89e87d0a8e6b9b8141c6273cbd570511 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script> | |
function asPromise(req) { | |
return new Promise((resolve, reject) => { | |
req.onerror = (e) => reject(e.target.error); | |
req.onsuccess = (e) => resolve(e.target.result); | |
}); | |
} | |
function openDBWithVersion(version) { | |
return asPromise(indexedDB.open("foo", version, (db) => { | |
console.log("running onversionupdate", db.oldVersion); | |
switch (db.oldVersion) { | |
case 0: // 0 -> 1 | |
db.createObjectStore("person", {keyPath: "id"}); | |
case 1: // 1 -> 2 | |
var personStore = db.transaction.objectStore("person"); | |
personStore.createIndex("name", "name"); | |
} | |
})); | |
}; | |
async function main() { | |
try { | |
await asPromise(indexedDB.deleteDatabase("foo")); | |
} catch(err) {} | |
const db = await openDBWithVersion(2); | |
db.close(); | |
try { | |
await openDBWithVersion(1); | |
} catch(e) { | |
window.idberror = e; | |
alert(JSON.stringify({message: e.message, name: e.name})); | |
} | |
} | |
main().catch(e => { | |
console.error(e); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fails with
The operation failed because the stored database is a higher version than the version requested.
on FF.