-
-
Save abiank/2a4eab0145f9588bed17 to your computer and use it in GitHub Desktop.
export db
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
// 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