"upgradeneeded"
event is specifically triggered when a change in the schema is required, indicated by updating the version number. If no schema modifications are needed - for example, if you are just interacting with existing object stores - then you should utilize the "success"
event instead. It's important to note that an implicit transaction is automatically created within the "upgradeneeded"
event, eliminating the necessity to invoke transaction()
within this event.
var request = indexedDB.open("mydb", 1); // version 1
// This event is only triggered for newly created databases, before the "success" event
request.addEventListener("upgradeneeded", event => {
var db = event.target.result;
var planningObjectStore = db.createObjectStore("planningSave");
// Initialize the store with initial data
});
// This event is triggered after the successful opening of the database
request.addEventListener("success", event => {
var db = event.target.result;
var tx = db.transaction("planningSave");
var planningObjectStore = tx.objectStore("planningSave");
// Read data within the newly created transaction
});