JSFiddle - React, Tailwind, and code Playground
by taylorbuley
JavaScript
var data = [{id: 'bar' }, { id: 'bam' } ];
if ('webkitIndexedDB' in window)
{
window.IDBTransaction = window.webkitIDBTransaction;
window.IDBKeyRange = window.webkitIDBKeyRange;
}
// creating or opening the database
var db;
var request = window.indexedDB.open("mydatabase2");
request.onerror = function(event) {
console.log("error: ");
};
request.onsuccess = function(event) {
db = request.result;
console.log(db);
var objectStore = db.transaction(["myobjectstore"],IDBTransaction.READ_WRITE).objectStore("myobjectstore");
readAll(db);
};
request.onupgradeneeded = function(event) {
var db = event.target.result;
console.log('reconstr',db);
var objectStore = db.createObjectStore("myobjectstore", {keyPath: "id"});
}
function readAll(db) {
var trans = db.transaction(["myobjectstore"], IDBTransaction.READ_WRITE);
var objectStore = trans.objectStore("myobjectstore");
objectStore.openCursor( IDBKeyRange.lowerBound(0) ).onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
console.log("Name for id " + cursor.key + " is " + cursor.value.Subject);
cursor.continue();
}
else {
console.log("No more entries!");
}
};
}