HTML and CSS Reference
In-Depth Information
This shows that the database has a name and a version, but not much else at this point. The
version has been implicitly created for us, but we will see later in this chapter that it is pos-
sible to explicitly set this.
Next we will implement the initObjectStore method so that the database knows how to
store objects of a specific type. Unlike the Web storage API, IndexedDB is going to store
our objects directly rather than as serialized strings. IndexedDB can in fact store any data
type, including literal strings and numbers, but we are only interested in storing objects.
IndexedDB also relies on the concept of primary keys when storing objects. We can tell In-
dexedDB the property name that holds the primary key, and we can even ask IndexedDB to
generate these for us. In the storage engine the id property of the object always represents
the primary key.
//
In relational databases, all tables typically need a primary key. This can consist
of one or more columns, and the value for the primary key must be unique within
a table.
The following is the implementation for creating object stores in IndexedDB.
initObjectStore : function(type, successCallback, errorCallback) {
if (!database) {
errorCallback( 'storage_api_not_initialized', 'The storage engine has not been initialized');
}
var exists = false;
 
Search WWH ::




Custom Search