Skip to content

Instantly share code, notes, and snippets.

@ivan-leschinsky
Created January 22, 2016 12:51
Show Gist options
  • Select an option

  • Save ivan-leschinsky/f985a22eb024189121e8 to your computer and use it in GitHub Desktop.

Select an option

Save ivan-leschinsky/f985a22eb024189121e8 to your computer and use it in GitHub Desktop.
simple indexDB for js workers or another
// Create/open database
var db, dbVersion = 1, request = indexedDB.open("simpleDB", dbVersion)
request.onerror = function (event) {
console.log("Error creating/accessing IndexedDB database");
};
request.onsuccess = function (event) {
console.log("Success creating/accessing IndexedDB database");
db = request.result;
db.onerror = function (event) {
console.log("Error creating/accessing IndexedDB database");
};
db.createObjectStore("simple");
var transaction = db.transaction(["simple"], IDBTransaction.READ_WRITE);
var put = transaction.objectStore("simple").put('s;alkdjnflkasjdhf lkashjdf akey', 'token');
transaction.objectStore("simple").get("token").onsuccess = function (event) {
var token = event.target.result;
console.log("Got token!" + token);
};
}
//from here:
// https://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment