Finley, I am.

jQuery DB

Download

Click here to download the jQuery database plugin.

Basic Methods

$.db.open_db

Arguments

$.db.create_table (see example below)

Arguments

$.db.query

Arguments

Selecting Data

$.db.get()

This function is used to retrieve data from the table specified in the first argument.

$.db.get('prayers')

$.db.where()

This function specifies the where clause.

$.db.where('id', 1).get('prayers')

$.db.order_by()

This function specifies how to order the returning data. The first argument is the field, the second is the direction (DESC: descending, or ASC: ascending).

$.db.order_by('date', 'DESC').get('prayers')

$.db.limit()

This function specifies a limit on how many rows to load. The first argument is the limit, the second is the offset.

$.db.limit(10, 20).get('prayers');

Inserting Data

$.db.insert()

This function inserts data from the second argument into a table specified in the first argument. The second argument is an object.

$.db.insert('prayers', {id: null, prayer: 'For my fiancée\'s upcoming test.', date: (new Date()).getTime()})

Updating Data

$.db.update()

This function updates the data from the second argument in a table specified in the first argument. The second argument is an object. If a where clause is specified, it limits what is updated.

$.db.where('id', 1).update('prayers', {date: (new Date()).getTime()})

Deleting Data

$.db.del()

This function deletes data from the table specified in the first argument. If a where clause is specified, it limits what is updated.

$.db.where('id', 1).del('prayers')

Examples

Connect to a Database

//connect to database
$.db.open_db({
    shortName: 'prayers',
    version:   '1.0',
    name:      'Prayers',
    maxSize:   1048576 //allow up to 1 mb to be stored
});

Create a table

//create a table, named "prayers"
$.db.create_table({
    name: 'prayers',
    fields: [{
        name: 'id',
        type: 'INTEGER',
        extra:'PRIMARY KEY AUTOINCREMENT'
    }, {
        name: 'prayer'
    }, {
        name: 'date',
        type: 'INTEGER'
    }]
}, true);

Retrieve data

//select last 5 prayers from "prayers" table & append them to the body
$.db.order_by('date', 'DESC').limit(5).get('prayers', function (r) {
    for (var i=0, len=r.num_rows; i<len; i++) {
        $('body').append('<div>'+r.results[i].prayer+'</div>');
    }
}, function () {
    alert('an error has occurred');
});