I am trying to create mutiple schema with indexed db , the scripts that implemented is
const openDB = () => {
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Create multiple schema
// Create a dynamic Schema to append data
var open = indexedDB.open("ExcelExtension", 1);
open.onupgradeneeded = function () {
var db = open.result;
var store_sheet = db.createObjectStore("schema_1", { keyPath: "id" });
var index = store_sheet.createIndex("NameIndex", ["name.last", "name.first"]);
};
open.onupgradeneeded = function () {
var db2 = open.result;
var store_sheet2 = db2.createObjectStore("schema_2", { keyPath: "id" });
var index = store_sheet2.createIndex("NameIndex2", ["name.last", "name.first"]);
};
}
//html <button onlick="openDB()> Create DB
what did i do wrong ? there is no error in script but its only reflecting one schema in db
When i check on my database on browser, i can see only one schema was created
Review how event listeners/handlers work in JavaScript. There are generally two ways to register an event handler:
// way 1
thing.onsomeevent = myEventHandler;
// way 2
thing.addEventListener('someevent', myEventHandler)
Most of the time it does not matter which syntax you use because most of the time you are only registering one event handler.
However, sometimes there is a big difference. The difference between the two methods is that when you have multiple event handlers, in the property assignment approach it overwrites all event handlers registered with one event handler. In the second way, it does not overwrite.
You can only register multiple event handlers using the add event listener syntax.