Lovefield, the Javascript Relational Database

Posted by in Databases, HTML5

Today I am writting related to a Google project called Lovefield, and it is a Javascript Relational Database designing for developing web applications. I have met this projects thanks to the Google website where they have published all Open Source projects the contribute to, or they have develop, order by categories.

Here you have their creator, a googler, explaining what Lovefield is about:

Lovefield

The basic idea of Lovefield is to use relational models to develop webapps, by using a database either online either offline. The second feature is to simplify the IndexDB API (the base of Lovefield), and make a sintax closer to traditional SQL sintax. This feature is esential for code maintaining, because the indexDB sentences are really complex, and by using Lovefield, the task is simplified. As an extra feature, Lovefield is designed for avoiding code injections!

Lovefield is also designed not only for simple queries but also for complex one, using GROUP BY, ORDER BY, LIMIT, SKIP, givien too much power to this library. Of course, the main functions are SELECT, INSERT, UPDATE and DELETE, COMMIT or ROLLBACK.

Lovefield has been prepared also for joining tables, not only INNER JOIN but also LEFT, RIGHT and OUTER JOINs, always simplifying the code (IndexDB code is complex!)

Another cool feature of Lovafield is parametrized queries, and observable queries, and in case on element on a collection is updated, an event will be fired, making easy to refresh the UI content.

Another feature is transactions, that are desinged as they are in relational databases. It is based on data persistence, by using COMMIT and ROLLBACK!

To end with the features, there is an implementation of integrity checks, b-tree indexes, a query optimizer and a query analyzer. Cool tools for developers!

Lovefield is a designed for developers, avoiding browsers problems (it is cross-browser), and it has been tasted with several libraries commonly used such as jQuery, Angular, …

But, before continue with Lovefield, let’s meet the base of it: IndexDB.

IndexDB

Lovefield works using IndexDB, is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. This API uses indexes to enable high performance searches of this data. But, IndexDB is not yet a mature technology, is not fully implemented, in part because not all browsers supported it, so adopting this technology is risky.

IndexDB, conceptually, is designed as a NoSQL database (close to MongoDB) but implemente on the client (browser). It has advantages that storage is larger than a cookie, and the concept is more close to a database that localstorage or sessionstorage, and anyway, even every browser has its own limits (and are not equals).

IndexDB is prepared as a offline database too, persistence, because data should be ready for next session without conecting to a server.

IndexDB works under the concept of a collection of objects (tables, in relational databases), where an object is a structured clone algorithm (similar to JSON, but with more options).

IndexDB is limited when creating SELECT queries with more that one table (this feature is well implemented by Lovefield).

You have a large IndexDB tutorial on Mozilla’s website, but also you have available the official IndexDB documentation.

Personally, I have never used IndexDB in any of the projects I build because the API is too complex, you need to be good at Javascript, not the basic, and if you add that every browser has its particularities, a library such as Lovefield is fundamental for using database in the browser. I do use localstorage for storing the neccesary informationhe conseguido almacenar aquella información necesaria para mantener de una sesión a la siguiente, sin tanta complejidad. De ahí que no haya investigado más sobre IndexDB.

For the next entrance, let’s go coding with Lovefield!

Happy coding!

Google+ Comments - Comentarios Google+