Accessing IndexedDB
Learn how to access an IndexedDB object from the browser.
Asynchronous nature
IndexedDB API is asynchronous, and once the requested operation is completed, its corresponding DOM Event is triggered. In other words, the triggered event type can help us identify whether the performed operation is successful or not.
IndexedDB supports
Overview of IndexedDB operations
The steps below demonstrate how we interact with IndexedDB:
Create/Open a database.
Create/Access an
in the database.object store This is similar to tables in SQL Make transactions, like storing or requesting data.
Listen for the operation to complete using the respective DOM Event.
Accessing the IndexedDB database
To work in a database, we need to open a connection to a database, and we can do this using the open()
method.
For the open()
method, we should provide the following:
Name of the database
An integer value denoting the version of the database
The second point, the database version, is an optional argument. If it’s skipped, the default value will be 1
.
Get hands-on with 1400+ tech skills courses.