Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
As you can see in case 1, createObjectStore() accepts a second parameter that defines the key path of the object store. This is useful when you store objects: put() calls don’t need a second parameter—you can pass just the value (an object), and the key will be taken from the object property with that name.
The key path lets you retrieve a value by that property later, and it must be unique (every item must have a different value for that property).
The key can be set to auto-increment so you don’t need to track it in your client code:
db.createObjectStore('notes', { autoIncrement: true })
Use auto increment if your values do not contain a unique key already (for example, if you collect email addresses without an associated name).
Lessons in this unit:
| 0: | Introduction |
| 1: | Loading the idb library |
| 2: | Creating a database and a store |
| 3: | Adding data into a store |
| 4: | Retrieving data from a store |
| 5: | Deleting data |
| 6: | Migrations |
| 7: | ▶︎ Unique keys |