Доброго времени суток.
Вот весь код.
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB,
IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction,
baseName = "Base_0",
storeName = "Options";
storeName1 = "List";
let f = function() {};
let Rec = {};
function logerr(err){
console.log(err);
}
function connectDB(f){
var request = indexedDB.open(baseName, 1);
request.onerror = logerr;
request.onsuccess = function(){
f(request.result);
}
request.onupgradeneeded = function(e){
e.currentTarget.result.createObjectStore(storeName , { keyPath: "id" });
e.currentTarget.result.createObjectStore(storeName 1, { keyPath: "path" });
connectDB(f);
}
}
function getRec(Rec, f){
connectDB(function(db){
var request = db.transaction([storeName], "readonly").objectStore(storeName).get(id=0);
request.onerror = logerr;
request.onsuccess = function(){
Rec = request.result;
console.log(Rec);
f(request.result ? request.result : -1);
}
});
}
function getStorage(f){
connectDB(function(db){
var rows = [],
store = db.transaction([storeName], "readonly").objectStore(storeName);
if(store.mozGetAll)
store.mozGetAll().onsuccess = function(e){
f(e.target.result);
};
else
store.openCursor().onsuccess = function(e) {
var cursor = e.target.result;
if(cursor){
rows.push(cursor.value);
cursor.continue();
}
else {
f(rows);
}
};
});
}
function setRec(Rec){
connectDB(function(db){
var request = db.transaction([storeName], "readwrite").objectStore(storeName).put({Value : Rec, "id": 0});
request.onerror = logerr;
request.onsuccess = function(){
return request.result;
}
});
}
function delRec(Rec){
connectDB(function(db){
var request = db.transaction([storeName], "readwrite").objectStore(storeName).delete(Rec );
request.onerror = logerr;
request.onsuccess = function(){
console.log("Record delete from DB:", Rec);
}
});
}
document.addEventListener('DOMContentLoaded', function init() {
connectDB(f);
//Rec.width = 500;
//setRec(Rec);
//console.log(Rec);
getRec(Rec, f);
console.log(Rec);
}, false);