ORM for Google Gears

Since it looks like sqlite is going to be the db layer for Google Gears, a database abstraction layer may not be a very important feature, since we don’t exactly need portable SQL. However, an object-relational mapping library could come in handy.

gears-dblib didn’t take long to pop up, and you can bet we’ll see something close to ActiveRecord very, very soon. One less reason to get started with those offline-capable apps.

Here’s the example useage for gears-dblib

 var db = new GearsDB('gears-test');

    var bob = {id: 3, name: 'Bob', url: 'http://bob.com', description: 'whee'};
    db.insertRow('person', bob);
    db.insertRow('person', bob, 'name = ?', ['Bob']);

    db.selectAll('select * from person', null, function(person) {
       document.getElementById('selectAll').innerHTML += ' ' + person.name;
    });

    db.selectRows('person', 'name like ?', ['%'], function(person) {
       document.getElementById('selectRows').innerHTML += ' ' + person.name;
    });

    var person = db.selectRow('person', 'id = 1');
    document.getElementById('selectRow').innerHTML = person.name;  

    // update
    person.name = 'Harry';
    db.updateRow('person', person);
    person = db.selectRow('person', 'id = 1');
    document.getElementById('updateRow').innerHTML = person.name;

    // force
    person.name = 'Sally';
    db.forceRow('person', person);
    person = db.selectRow('person', 'id = 1');
    document.getElementById('forceRow').innerHTML = person.name;

    var adam = {name: 'Adam', url: 'http://adam.com', description: 'long hair'};
    db.forceRow('person', adam);
    person = db.selectRow('person', 'id = 4');
    document.getElementById('forceRow2').innerHTML = person.name;

    db.deleteRow('person', bob);

About John Herren

John Herren is a developer and technical consultant with focus on web applications. He currently serves as Director of Development for Primetime US, the company behind the hit movie and book The Secet. John was formerly staff writer and developer community evangelist for Zend Technologies. Along with founding neat experiments like TagCloud.com, John is an active member in the mashup community, working with API providers and speaking at conferences. He is a published author of Linux certification study material. John enjoys using open source software like PHP and Ruby on Rails to bend the web into exciting new chimeras of hyperlinked goodness. View all posts by John Herren

One response to “ORM for Google Gears

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: