php[architect] logo

Want to check out an issue? Sign up to receive a special offer.

Impel, the Javascript ORM

Posted by on March 23, 2010

Impel is an object-relational mapper for Javascript, which takes advantage of the future native support of browsers for relational client-side databases.


The in-development HTML5 specification is becoming more and more supported by browsers such as Firefox, Safari and even Internet Explorer. Together with other standardizations, the specification defines a per-host relational database for data storage on the client side, to be accessed via JavaScript without any additional requirement than SQL knowledge.
Currently SQLite is used by all the browsers’ implementations, as it is the most popular lightweight relational database.

However, the available data model is not really limited to the relational one.

The solution

As often is the case, where there is a relational database, there is also an object-relational mapper. In JavaScript every variable is an object, so it makes sense to build an object-oriented application model, and transparently persist the data.

Thus the need for a DataMapper, like Impel, to store these objects automatically in the native database via metadata provided in the source code. Of course Impel comes with an automatical synchronization package for updating the rapidly changing schemas distributed all over the client machines. And it runs on the iPhone, as the authors like to point out.

Technology overview

Impel is built over MooTools, which is a required dependency. The API is modeled on Propel. Propel was one of the first object-relational mappers for PHP 5.

The original API is modified to accommodate an asynchronous model, which the JavaScript interpreters require. Blocking calls in JavaScript do not work very well, since with the usage of simple method calls the browser would effectively freeze while expecting that the database computes and returns its query result. Asynchronous model means that handlers (anonymous or named functions) are registered on querying, and are called when the result is available, fitting in the event-driven paradigm of JavaScript programming.

Impel is indeed a bleeding edge technology, but a standout in the new HTML5 environment. It fills the gap between JavaScript objects and the native local storage of HTML5, a significant feature especially for early adopters.

Marco is the keeper of keys and Chief Garbage Collector at Blue Parabola. He can be found on Twitter as @mtabini.
Tags: , , , , , ,

Leave a comment

Use the form below to leave a comment: