HTML and CSS Reference
In-Depth Information
IndexedDB Implementation
We will now implement the storage engine using the IndexedDB API. Due to the fact we are
using the same API we will not need to change anything else in our application. The tasks-
controller.js does not care how the storage engine is implemented, only that the API behaves
as advertised.
IndexedDB is a more sophisticated API than Web storage. Although it is an object database
rather than a classic relational database, it incorporates concepts that are familiar to those
who have worked with relational databases, such as transactions and indexes.
IndexedDB always operates with asynchronous callbacks, but by default it does still use the
main browser thread. It is also possible for browser vendors to implement the IndexedDB
API with Web Workers (a subject that will be introduced in later chapters), which allows
processing to occur on a separate thread.
Not all major browsers currently support IndexedDB. In addition, some browsers do not
support it through the “indexedDB” object, only through a vendor named object (e.g. mozIn-
dexedDB in Firefox, msIndexedDB in IE). This is used to indicate that the browser does not
provide full compliance with the specification. The implementation below will ignore these
alternatively named implementations.
To begin implementing the API, create a new file in the scripts folder called tasks-indexed-
db.js. Inside this add the skeleton of our API:
storageEngine = function() {
return {
init : function(successCallback, errorCallback) {
},
initObjectStore : function(type, successCallback, errorCallback) {
},
save : function(type, obj, successCallback, errorCallback) {
},
findAll : function(type, successCallback, errorCallback) {
},
delete : function(type, id, successCallback, errorCallback) {
},
findByProperty : function(type, propertyName, propertyValue, successCallback, errorCallback) {
},
findById : function (type, id, successCallback, errorCallback) {
Search WWH ::




Custom Search