HTML and CSS Reference
In-Depth Information
// value is the stored object
data.push(cursor.value);
}
// get the next object
cursor.continue();
} else {
callback(data);
}
};
}
// example usage
find(function (data) {
return data.rating > 5;
}, function (found) {
alert('Found ' + found.length + ' videos with a high
¬ rating');
});
Deleting and dropping
data like a hot potato
What if you made a mistake or want to remove data? Maybe
you've had complaints about Bruce's latest film, Banana Smash,
Pink Fury, and you need to delete it.
The process is exactly the same as the get method, except we
call the delete method when passing in the key (note that for
this, you'll need write permissions too):
var transaction = db.transaction(['blockbusters'],READ_WRITE),
store = transaction.objectStore('blockbusters'),
request = store.delete(key);
There's also a method for clearing an entire object store: clear.
The clear method doesn't take any arguments and the process,
again, is exactly the same.
There are two more ways of clearing data: deleteObjectStore
and deleteDatabase . The method names are fairly self-explana-
tory, but they're not as simple to use.
deleteObjectStore can only run from a transaction. The method
sits on the database object (the result of the indexedDB.open
method). However, you can't delete the object store using a regu-
lar transaction. You can only delete the object store from a set
 
Search WWH ::




Custom Search