I have been trying out implementations of IndexedDB on various browsers over the weekend and here are the examples using TrialTool. The browsers used were
- Internet Explorer 8 with the IndexedDB prototype.
- Firefox 4.0 Beta 8
- Google Chrome Canary build 10.0.624.0
There were some differences in the API which I hope gets ironed out before the final release. Some of the differences in the API between Internet Explorer (IE), Firefox (FF) and Chrome (CH) are as follows.
Prerequisites
In case of IE, the activeX object needs to be initialized. In case of FF and CH, the properties are moz_indexedDB (mozIndexedDB in FF4B9) and webkitIndexedDB. Some other properties like ranges and constants (like webkitIDBRange, etc) also need to be initialized to the common property.
Transactions
The IE implementation allows an explicit close method while the transaction is automatically closed in case of FF and Ch when it goes out of scope.
Creating Object Store
The specification can only be created in a version change scope. IE does not enforce this yet. In case of FF and IE, the keyPath is specified as strings, while CH requires a json literal of the form {"keyPath" : "field_name"}. FF4b9 will follow the json object for the second argument.
Object and Key Cursors
IE and FF have a method to openObjectCursor, that is openCursor in CH. On CH, the openKeyCursor is the equivalent of openCursor on FF and IE. FF4b9 will follow the standards and use the methods like CH.
Unimplemented GetAll and Clear methods
CH does not implement getAll and clear method on ObjectStore.These are FF only methods but are really useful. Hope it gets into the standard.
Transactions in setVersion
Creating and removing Indexes in the version change transaction scope is interesting. In the onsuccess(event) callback, it is available as the event.result in CH and event.transaction in FF. It will change to event.result in FF4b9.
The list of differences is not exhaustive; if you find any interesting facts, please do drop in comments.
The source is located at https://github.com/axemclion/ttd/tree/gh-pages/IndexedDB.
Thanks to Ben Turner from Mozilla for providing inputs for the indexes and changes coming in for Firefox 4, Beta 9. Can't wait for the next version !! :)