Monday, November 28, 2011

IndexedDB APIs & Javascript.Next

Of the various specifications that are considered a part of HTML5, the IndexedDB API is one of the few APIs that are independent of the DOM and are impacted by Javascript. It would be an interesting to analyze the impact of newer Javascript features to this API set.
This post looks at current features of ECMA5 in addition to proposals in Harmony. I had previously posted slides for a talk on IndexedDB and the last slide touched briefly about this.

The module pattern has been widely accepted as a useful feature, thanks to CommonJS and specifically NodeJS implementations. Today, the IndexedDB object is a property of the global Window or WebWorker Objects. With modules, IndexedDB can be included into the code using something like require("IndexedDB") for async and require("IndexedDBSync") for the sync version of the API. With this distinction, will developers be allowed to use the sync version in non-web worker environments also?

Like modules, the promises pattern is also gaining traction. Currently, all Async operations on IndexedDB are on a IDBRequest Object. Should IDBRequest be changed to follow the Promises pattern?

Transaction Scope with Let and Var
With the changes in variable scopes using the let and var keywords, transaction scope will also be impacted. Transactions today auto-commit when the transaction variable goes out of scope and no more requests can be placed against it. With the Let statement, this could happen sooner inside blocks allowing even shorter transactions. This would also avoid closure related confusions in transaction scopes. This would also ensure that transactions variables are not leaked into the global scope.

Iterating over a cursor today is done using a cursorRequest. Similar syntax should be used for iterating over cursors. The cursor.continue could be replaced with the iterator next method and the cursor could be treated as a collection. However, it would be interesting to see how the update and delete method on the cursor change for the new iterator pattern.

Generator Expressions and Array Comprehensions
While iterating over cursors, developers mostly perform some operations on the current item.Generator expressions are based on array comprehensions and make sense here, given the asynchronous nature of the API. Additionally, Array functions like each, filter, some, etc could also eliminate a lot of cursor boiler plate code. 

Destructuring Assignments
Continuing the discussion about cursors, the cursor.value and cursor.key return the key and the value respectively. However, restructuring assignments like [key, value] = cursor.continue() would help extract the keys and values easily. Similarly, doing something like [objectValue, key] = objectStore.get(id) could also be a useful notation.

Binary Blobs
With the introduction of Binary Blobs, specially for file, WebGL and devices API, it would be interesting to see how the databases (LevelDB or SQLite) store binary data and how they impact the quotas. I am guessing that indexing based on Binary Data would not be possible in the near future.

READ_WRITE/READ transaction modes and Object Freeze/Seal
Objects can be frozen or sealed to prevent them from being manipulated. In case of a READ transaction, the object obtained with a get or in cursors could be sealed and frozen to indicated that it was obtained from a READ transaction as opposed to a READ_WRITE transaction. This may however be an extreme way to indicate the transaction type.

Object Getters and Setters
With objects now having the ability define custom getters and setters, developers can use this method to provide a transparent abstraction that persists objects when properties are changed or loaded from a database when objects are read. Combining this with a Hibernate like query language could do ORM-magic that are traditionally done only with server-side languages. However, the logic on when to do (lazy vs eager) an async write or read would require some thought.

With the introduction of classes, it would be interesting to see schema for Object Stores. This may also change the way IndexedDB implementations could possibly change the way objects are stored internally. For example, IndexedDB on Firefox stored Blob for objects in SQLite today.

I have not come across similar documentation that discusses how IndexedDB works with new constructs in Javascript and I think this is an interesting topic of discussion. Please leave your opinions in the comments.


Rashid said...

The easiest system to get paid 2% dayly. And this since many years now. Try it yourself

Rightshoppingkitchenappliances said...

Kitchen works are synergistic with the proper gadgets.
Proper gadgets not just assure the proper utilization of the ingredients, but
also serve the safety concern of user as well. Maharaja is all here at make the real cooking boost for the

Supriya Chaudhuri64 said...

Ace servicing from Onida in the household appliance segment has really been something to watch out for.
Kitchen gadget shoppers are lucky to have the glimpses of its services. Yet again, the service from Onida meets the core preference area of the shoppers. Visit for more.

Gargi Bose said...

Kitchen appliances are
equally important for household decoration. Besides coming handy to prepare
delicious stuffs, theses appliances are the style contributors as well. LG
appliances play this dual role playing quiet beautifully, and the visitor can
get them all at

Karbonn Cell said...

The brand reputation that Karbonn has in its
intangible asset has worked in this venture as well. Besides the workability,
mobiles are the specialists in showing your right fashion statement. From smart
phones to normal usage one, Karbonn is really zeroing on the cost effective
mobiles. Visit

alokitabose said...

Accessories do compliment the looks, and
leather made stuffs are just indispensable in that. Numerous brands have excelled
in that, and getting them all under a single address is definitely the sought
after one. makes it possible, and is the link to visit.

security equipment said...

I would like to thank you for the efforts you've made in writing this posting. I'm hoping the same very best function from you inside future too. 

Gargi Bose said...

People are hard to come by who doesn’t prefer outing. However, it’s the proper planning that makes
the tour program successful, and it needs the expert handling to ensure that. Indeed, just a click onto the and the world goes exploring.

Giftflowersusa12 said...

Special relations always occupy
special place in heart, and deserves special gifts to pay tribute to them. Be
it flowers, be it foods, be it something else, your gifts are your identity.
Visit for more information.

Traveltour said...

Maintaining multiple connections have become easy now, thanks to the dual SIM stuffs. The mobile majors are all busy in deigning these doubly utility set in masses, and rightly so, the service from is in the picture. The link at brings the details out.

avi majumdar said...

Keep up the good work. Best of luck.

JoydipGhosh said...

Website is very comprehensive and informative. I have enjoyed the visit. From


JoydipGhosh said...

Website is very comprehensive and informative. I have enjoyed the visit. From


Post a Comment