HTML and CSS Reference
In-Depth Information
verRequest.onsuccess = function (event) {
// now we're ready to create the object store!
verRequest.onerror = function () {
console.log('unable to set the version :(');
Once the success event fires we can create our new object
stores using the setVersion method.
Creating object stores
Inside the version control success event handler, create new
object stores as follows:
var verRequest = db.setVersion(version);
verRequest.onsuccess = function (event) {
var store = db.createObjectStore('blockbusters', {
keyPath: 'title',
autoIncrement: false
// at this point we would notify our code
// that the object store is ready
For this application we've created a single object store, but in our
next version we might choose to add an object store for direc-
tors of the movies in our video database. What's important in the
createObjectStore method is the options argument we passed.
This tells the object store that there should be an index (used to
retrieve the blockbuster movie) and that its ID should not auto-
matically increment; in fact, the autoIncrement flag is false by
default; I've included it simply to show you how it could be used.
When it comes to storing new objects now, I must ensure the
video has a unique title property, which will be indexed by
IndexedDB for fast retrieval later.
Perhaps we're going to store the director name in the block-
buster video data, and not in a separate object store. In addi-
tion, I want to be able to search by director, so we add another
index to our datastore:
store.createIndex('director', 'director', { unique: false });
Search WWH ::

Custom Search