JQuery plugin for IndexedDB API - version upgrade

A new version of the Jquery library for IndexedDB API has been released and here are some useful links for you to get started.

In my last post, I had written about the updates to the examples for IndexedDB based on the latest version supported on Firefox 12. The most significant change was the removal of the setVersion method and introduction on the onupgradeneeded paradigm. This method gives us a new perspective on how we manage object stores and indexes in IndexedDB.
Over the past few days, I have also updated the Jquery plugin for IndexedDB to reflect this change. Though the "onupgradeneeded" method is only available in Firefox as of now, other browsers will soon implement it. The new version of the library is currently implemented as jquery.indexeddb.new.js but will eventually be called jquery.indexeddb.js. Note that for now, the file jquery.indexeddb.js still points to the older version that works with the implementation of IndexedDB in the stable versions of the browser.
In addition to adding support of onupgradeneeded, some other parts of the API have also changed. Here is the structure of the new API.
  • $.indexedDB(database_name) is the way to open the database to the latest version
  • $.indexedDB(database_name, schema) initializes the database with the schema.
  • $.indexedDB(db_name).transaction(store_names).progress(transactionMethod) can be used to enclose a set of CRUD operations in a transaction.
  • transaction.createObjectStore() can be used to create object stores inside the transaction method.
  • $.indexedDB(db).objectStore(name).add() is a shorthand for creating a transaction with just the single add operation.
  • $.indexedDB(db).objectStore(name).each() can be used to iterate over the objects in the store. 
  • $.indexedDB(db).objectStore(name, true) is a short hand to create an object store if it does not exist.
For a detailed list of APIs, you can take a look at the API documentation
As indicated in the original blog post about the guidelines for this API,
  1. The API has a good support for method chaining for quick and shorthand operations without having to write boiler plate code like in the native IndexedDB API.
  2. Another example of short hand operations is the use of implicit transactions using the .objectStore() syntax. Not all IndexedDB CRUD operations have to be explicitly in a transactions.
  3. Use of Jquery Deferreds makes it gel well with other parts of Jquery and frameworks that use Jquery. 
  4. Errors bubble up the method chain and hence are not required to be checked at every step of the API. 
  5. Smart defaults in the form of range, direct, automatic object store creation, etc, make it easy to start using the API without sacrificing the flexibility. 
If you have a  live project that is data intensive and where it makes sense to cache some data at the client, you could give this plugin a try. However, it may take some time before the IndexedDB implementation in browsers itself is ready for production.