Skip to content

Instantly share code, notes, and snippets.

@toots
Created March 11, 2013 18:39
Show Gist options
  • Save toots/5136523 to your computer and use it in GitHub Desktop.
Save toots/5136523 to your computer and use it in GitHub Desktop.
IndexedDb export function.
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