Created
March 11, 2013 18:39
-
-
Save toots/5136523 to your computer and use it in GitHub Desktop.
IndexedDb export function.
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
exportDb = (name, cb) -> | |
handler = indexedDB.open(name) | |
handler.onsuccess = (sender) -> | |
db = sender.target.result | |
stores = db.objectStoreNames | |
results = {} | |
transaction = db.transaction stores, "readonly" | |
transaction.onerror = transaction.onabort = (event) -> | |
cb event, null | |
transaction.oncomplete = -> | |
cb null, results | |
_.each stores, (store) -> | |
results[store] ||= [] | |
transaction.objectStore(store).openCursor().onsuccess = (event) -> | |
return unless cursor = event.target.result | |
results[store].push | |
key : cursor.key | |
value : cursor.value | |
cursor.continue() | |
handler.onerror = (event) -> | |
cb event, null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment