HTML and CSS Reference
In-Depth Information
Listing 5.9. app.js—Feature detection for database-related objects
5.3.2. Creating or connecting to an IndexedDB database, creating an obje- ect store
and index
To create or connect to an IndexedDB database, the application needs to invoke the
IndexedDB method open . If no database exists when the open method is called,
a new database will be created, and a connection object will be created. Once in-
dexedDB.open successfully creates a connection, the onsuccess and/or up-
gradeNeeded event handler will be called, and the connection object will be accessible
through the event object passed to the event handler. [ 1 ] With this connection object, the ap-
plication can create an object store or index for the application.
1 If a new database is created, events upgradeNeeded and onsuccess will be fired, but upgradeNeeded
will be handled before onsuccess .
Before looking at how an application would create object stores and indexes, let's discuss
how data is stored in an IndexedDB database. All data in an IndexedDB database is stored
inside an object store. Each database can contain many object stores, which can be roughly
thought of as equivalent to tables in a relational database management system (RDBMS).
In turn, each object store comprises a collection of zero or more objects, the equivalent of
rows in a RDBMS. Figure 5.4 illustrates the structure of an IndexedDB database.
 
 
Search WWH ::




Custom Search