lundi 27 septembre 2010

Localdatabase released

I'm pleased to announce the availability of localdatabase. Localdatabase is a database abstraction layer that provides fluent interfaces for more readable code. It now supports Google Gears database. Recently, I spent 20 caffeine-fueled days building offline support for an existing enterprise J2EE monolithic application for a pharmaceutical company based in Barcelona. The magic of this Javascript framework is that it suits any kinds of legacy applications provided that you use Google Gears. I learned a lot over the course of those 30 days and even more after launching the functionality and hoped to share this production with other developers looking to work with Gears. It's now released on Google Code. You can download it here. What lies beneath is a clean support of Web Storage and Web Database APIs. It is in progress and I will update you. It will be the logical progression from Google Gears. Upgrading localdatabse for full HTML5 Web database support will not affect the API interface. It is just a matter of adding a simple wrapper of this asynchronous API. For Google gears, i implemented a simple wrapper of the Google Gears Database API. Currently, there are tons of Javascript framework that provides an abstraction layer such as gears-db-lib or sqljs. So what 's localdatabase good for ? Well, from a developer perspective, it helps writing readable code and it is undoubtedly essential for any applications. I kept as much as possible the SQL semantics. Passing in the wrong parameters won 't happen. The core aspect of localdatabase is the use of method-chaining pattern and the end result is quite interesting. Here's the code to select the 12-year-old kids living in Paris ordered by name:
_db.from("PERSON").where({age:12,location:"PARIS"}).order({name:"ASC"}).each(function(kid) { alert('Hey my name is ' + kid.name); });
Its use is simple. Instead of using a callback you now using Localdatabase chaining to execute all the methods that you need. What 's more is that it eases common database tasks like data exports or drop-creating. For instance, to export your data in a JSON format with Jquery: var lines = _db.from("ORDER_LINE").list();
var orders = _db.from("ORDERS").list(); var export_data = $.toJSON([{"lines":lines},{"orders":orders}]); // you can send it now
If you have any request, please do not hesitate contacting me. Contributors are welcome!