Storing objects
Storing objects is pretty simple, assuming you have appropriate error handlers at the database and transaction level. You can track events for each object you store; but this is a quick way to become overwhelmed if you're storing a lot of data.
Note
The snippets in this section are located at snippets/07/ex4-store-objects/*
in the code package of this book. When using the interactive snippet playground, select 7: IndexedDB and the examples from 4a to 4b.
There are two ways you can store an object: you can add it or you can put it. Here are the differences between both methods:
add
: This will store an object. The object must not already exist in the store. The object must satisfy any unique keys and indexes or an error will be generated.put
: This will store an object if the object doesn't exist and it will update an object if the object is already present in the store. The object must satisfy any unique keys and indexes or an error will be generated.
Once you have a readwrite...