-
Notifications
You must be signed in to change notification settings - Fork 5
Managing the Database
perrygeorget edited this page Dec 29, 2013
·
7 revisions
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);
- Database name
- Version number
- Text description
- Size of database
- Creation callback function
What is returned is an instance of a JQueryDatabase object.
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);
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);
});
To get the current database version:
var db = $.db("people", "", "People Database", 1024 * 1024, callback);
var version = db.getVersion();