Created
January 22, 2016 12:51
-
-
Save ivan-leschinsky/f985a22eb024189121e8 to your computer and use it in GitHub Desktop.
simple indexDB for js workers or another
This file contains hidden or 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
| // 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