Skip to content

Instantly share code, notes, and snippets.

@abiank
Forked from toots/gist:5136523
Last active August 29, 2015 14:04
Show Gist options
  • Save abiank/2a4eab0145f9588bed17 to your computer and use it in GitHub Desktop.
Save abiank/2a4eab0145f9588bed17 to your computer and use it in GitHub Desktop.
export db
// Generated by CoffeeScript 1.6.3
(function() {
var exportDb;
exportDb = function(name, cb) {
var handler;
handler = indexedDB.open(name);
handler.onsuccess = function(sender) {
var db, results, stores, transaction;
db = sender.target.result;
stores = db.objectStoreNames;
results = {};
transaction = db.transaction(stores, "readonly");
transaction.onerror = transaction.onabort = function(event) {
return cb(event, null);
};
transaction.oncomplete = function() {
return cb(null, results);
};
return _.each(stores, function(store) {
results[store] || (results[store] = []);
return transaction.objectStore(store).openCursor().onsuccess = function(event) {
var cursor;
if (!(cursor = event.target.result)) {
return;
}
results[store].push({
key: cursor.key,
value: cursor.value
});
return cursor["continue"]();
};
});
};
return handler.onerror = function(event) {
return cb(event, null);
};
};
}).call(this);
/*
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