Skip to content

Instantly share code, notes, and snippets.

@sergi
Created November 10, 2014 08:26
Show Gist options
  • Save sergi/e68f6b3cca60bcf39fd9 to your computer and use it in GitHub Desktop.
Save sergi/e68f6b3cca60bcf39fd9 to your computer and use it in GitHub Desktop.
var DBNAME = 'tabgrenade';
var DBVERSION = 1;
var STORENAME = 'keyvaluepairs';
var db = null;
function withStore(type, f) {
if (db) {
f(db.transaction(STORENAME, type).objectStore(STORENAME));
} else {
var openreq = indexedDB.open(DBNAME, DBVERSION);
openreq.onerror = function withStoreOnError() {
console.error("asyncStorage: can't open database:", openreq.error.name);
};
openreq.onupgradeneeded = function withStoreOnUpgradeNeeded() {
// First time setup: create an empty object store
openreq.result.createObjectStore(STORENAME);
};
openreq.onsuccess = function withStoreOnSuccess() {
db = openreq.result;
f(db.transaction(STORENAME, type).objectStore(STORENAME));
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment