HTML and CSS Reference
In-Depth Information
Figure 5.4. Hierarchical structure of an IndexedDB database. Each database can have many object stores, which
themselves can contain many objects. The object is the structure for a data record, equivalent to a row in a
relational database.
Now that you have a better idea of how objects are stored in the IndexedDB database, let's
get back to creating object stores and indexes.
Object stores can only be created while the application is handling an upgradNeeded
event. This event can occur in two situations: when a new database is created and when
a database's version number is increased. Once the application has entered the up-
gradeNeeded event handler, the object store is created by calling the createOb-
jectStore method with two arguments: a name and keypath for the new object store.
The keypath defines what property within each object will serve as the key for retrieving
the object from its store.
Once the object store is created, you can create one or more indexes for it. Creating an in-
dex allows the application to retrieve an object with a key different than the one defined in
the object store. To create a new index, use the object store's method createIndex and
pass it three arguments: the name of the new index, the name of the object property that
will serve as the key, and an options object.
Search WWH ::

Custom Search