Transaction undefined error when creating object store in indexedDB -
Transaction undefined error when creating object store in indexedDB -
i have problem code hope can help me with. i've set .open , it's next code (unupgradeneede, onsuccess, onerror aso.) in js file , phone call js file. seems code openingen indexeddb , creating object stores never executes. code
window.indexeddb = window.indexeddb || window.mozindexeddb || window.webkitindexeddb || window.msindexeddb; contosodata = { db: null, usedb: function (successcallback) { var request = window.indexeddb.open("contosodata", 2); request.onsuccess = function (e) { contosodata.db = request.result; console.log('indexeddb.success'); successcallback(); }; request.onupgradeneeded = function (e) { console.log('indexeddb.upgradeneeded'); contosodata.db = e.target.result; if (contosodata.db.objectstorenames.contains("bookingstore")) { contosodata.db.deleteobjectstore("bookingstore"); var bookingstore = contosodata.db.createobjectstore("bookingsstore", { keypath: "id", autoincrement: true }); bookingstore.createindex = ('title', 'title', { unique: false }); bookingstore.createindex = ('id', 'id', { unique: true }); } else if (contosodata.db.objectstorenames.contains("workerstore")) { contosodata.db.deleteobjectstore("workerstore"); var workerstore = contosodata.db.createobjectstore("workerstore", { keypath: "employeenr" }); } else if (contosodata.db.objectstorenames.contains("customerstore")) { contosodata.db.deleteobjectstore("customerstore"); var customerstore = contosodata.db.createobjectstore("customerstore", { keypath: "orgnr" }); } var machinestore = contosodata.db.objectstorenames.contains("machinestore", { keypath: "machinenr" }); contosodata.db.deleteobjectstore("machinestore"); var machinestore = contosodata.db.createobjectstore("machinestore"); }; request.onerror = function (e) { console.log('indexeddb.onerror: ' + e); }; request.onblocked = function (e) { console.log('indexeddb.locked'); }; } }; contosodata.usedb(function (db) { var transaction = contosodata.db.transaction(['bookingsstore'], 'readwrite'); var objectstore = transaction.objectstore('bookingsstore'); console.log(objectstore.name); });
and then, when seek run it, transaction undefined when seek create transaction in other js-file... i've checked js-file function open indexeddb linked in right way , order html-file. i've set breake points , looks usedb code never execute. code
function init() { contosodata.usedb(); calendar.createcalendar(); } calendar.createcalendar = function () { var transaction = contosodata.db.transaction(["bookingstore"], "readwrite"); var bookingstore = transaction.objectstore("bookingstore"); }
is there i'm missing? searched , tried find solution without success far...
will this
function init() { calendar.createcalendar(); } calendar.createcalendar = function () { var transaction = contosodata.db.transaction(["bookingstore"], "readwrite"); var bookingstore = transaction.objectstore("bookingstore"); } contosodata.usedb(init);
indexeddb
Comments
Post a Comment