Solution Review: Handling Employee Details
Review the solution for the IndexedDB challenge on handling employee details.
We'll cover the following...
Solution
The code below contains the solution for all the tasks from the previous lesson:
Code explanation
Task 1: We create the Company database and add an Employee object store.
Line 2: We retrieve the button with the
init_dbID and store it in a variable.Line 3: We create a variable to hold the database object that can be used in all the functions.
Line 4: We add the click event listener to the
initDatabasebutton.Line 6: Inside the click handler, we use the
open()method to open a new connection to theCompanydatabase. A new database will be created if the database isn’t already present. During the new database creation, we trigger theupgradeneededevent.Lines 7–10: We add the
successevent handler to the open database request. Inside ...