Last active
December 19, 2015 02:19
-
-
Save sethladd/5882605 to your computer and use it in GitHub Desktop.
How to open two indexeddb stores, one after another?
This file contains 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
Database db; | |
window.indexedDB.deleteDatabase('justtesting') | |
.then((_) { | |
print('opening'); | |
return window.indexedDB.open('justtesting', version: 1, | |
onUpgradeNeeded: (e) { | |
print('upgrading to v1'); | |
Database d = e.target.result as Database; | |
d.createObjectStore('store1'); | |
}, | |
onBlocked: (e) => print('blocked on 1')); | |
}) | |
.then((_db) => db = _db) | |
.then((_) => db.close()) | |
.then((_) { | |
return window.indexedDB.open('justtesting', version: 2, | |
onUpgradeNeeded: (e) { | |
print('upgrading to v2'); | |
Database d = e.target.result as Database; | |
d.createObjectStore('store2'); | |
}, | |
onBlocked: (e) => print('blocked on 2')); | |
}) | |
.then((_db) => db = _db) | |
.then((_) { | |
print('fetching data'); | |
Transaction txn = db.transaction('store1', 'readonly'); | |
ObjectStore store = txn.objectStore('store1'); | |
store.getObject('1').then(print); | |
return txn.completed; | |
}) | |
.then((_) { | |
print('all done'); | |
}) | |
.catchError(print); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you're block because you open with 2 differents version number :
from https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB