How to get started on using IndexedDB? Beginners guide!
27 November, 2022
8
8
2
Contributors
IndexedDB - In-build browser storage
1. What is indexedDB?
•
•
•
Indexed Location
2. When to use indexedDB or indexedDB use cases?
•
•
•
•
Opening/Creating your first DB in IndexedDB
1. Opening and event handling
Empty DB
That's all there is on how to open the database, what you need is just - indexedDB.open(param1, param2);
param1 is where you give the name of the database and param2 is the version of the DB. So, it looks like this- indexedDB.open(name, version);
The Opened DB
Console.log(openRequest)
onerror
-> It is the event that is triggered whenever there is an error opening/connecting to the database, although there is very less chance of the request failing in indexed, but yes this event is triggered whenever there is an error opening the DB. Let's look into it with a code sample -
Here my initial version was 3 and later I tried to change it to 1
onsuccess
-> It is the event that is triggered whenever the IDBRequest succeeds. Let's look into it with a code sample -
The event is automatically triggered whenever the request is successful
onupgradeneeded
-> This event is fired/triggered when a bigger version than the existing version is loaded.
Only if
onupgradeneeded
handler finishes without errors,openRequest.onsuccess
triggers, and the database is considered successfully opened.
2. Object Stores/Structuring the database
Now, let's structure the database through object stores. Also, check out IDBObjectStores for details of different types properties and methods.
Now let us check out its use cases, don't worry we will be discussing briefly whatever method or property we use along the way.
The DB with object stored
•
•
DB deleted
•
Conclusion/Summary of this blog
•
•
•
•
•
javascript
database
develevate
howto
indexeddb