Skip to content

Managing the Database

perrygeorget edited this page Dec 29, 2013 · 7 revisions

Creating a Database

As described in the Getting Started section of this document, creating a database is very easy.

var db = $.db("people", "", "People Database", 1024 * 1024, callback);
  1. Database name
  2. Version number
  3. Text description
  4. Size of database
  5. Creation callback function

What is returned is an instance of a JQueryDatabase object.

Creation Callback Function

Using the creation callback function, schema can be created and an initial dataset created.

var callback = function (db) {
    db.createTable(...).insert(...);
});
var db = $.db("people", "", "People Database", 1024 * 1024, callback);

Versioning a Database

Versions can be migrated between a current version and the latest version. By adding one or more migrations and them bumping the version.

var db = $.db("people", "", "People Database", 1024 * 1024, function (db) {
    db.addVersionMigration("", 2.0, function (transaction) {
        // do all the things
    });
    db.addVersionMigration("1.0", 2.0, function (transaction) {
        // do some of the things
    });
    db.addVersionMigration("1.5", 2.0, function (transaction) {
        // do a few things
    });

    var successCallback = function () {
        // do something good
    };
    var errorCallback = function(error) {
        // do something else
    };
    db.changeVersion("2.0", successCallback, errorCallback);
});

Current Database Version

To get the current database version:

var db = $.db("people", "", "People Database", 1024 * 1024, callback);
var version = db.getVersion();

Clone this wiki locally