-
Notifications
You must be signed in to change notification settings - Fork 5
Manipulating Tables
perrygeorget edited this page Jan 7, 2014
·
10 revisions
Tables can be created by calling the createTable function.
var params = {
name: ...,
columns: ...,
constraints: ...,
dropOrIgnore: ...,
done: ...,
fail: ...
};
var db = $.db("people", "", "People Database", 1024 * 1024, callback);
db.createTable(params);
The name property of the object passed to the createTable function will be the name of the table that is created.
The are two ways to define the columns of a table:
-
As a complete statement or
var db = $.db("people", "", "People Database", 1024 * 1024, callback); db.createTable({ name: "person", columns: [ "id INTEGER PRIMARY KEY AUTOINCREMENT", "name TEXT NOT NULL", "male INT DEFAULT 1" ] }); -
As an object with attributes.
var db = $.db("people", "", "People Database", 1024 * 1024, callback); db.createTable({ name: "person", columns: [ { name: "id", type: "INTEGER", constraint: "PRIMARY KEY AUTOINCREMENT" }, { name: "name", type: "TEXT", constraint: "NOT NULL" }, { name: "male", type: "INT", constraint: "DEFAULT 1" } ] });
Constraints can be applied to the table as well.
var db = $.db("people", "", "People Database", 1024 * 1024, callback);
db.createTable({
name: "person",
columns: [
"id INTEGER AUTOINCREMENT",
"name TEXT NOT NULL",
"male INT DEFAULT 1"
],
constraints: [
"PRIMARY KEY (id)",
"UNIQUE (name)"
]
});
The dropOrIgnore parameter can be added to the object that is passed to the createTable function.
| Value | Explanation |
|---|---|
drop |
If a table by the name provided exists, drop it and create a new table as defined in its place. |
ignore |
If a table by the name provided exists, do not create a new table. |
TODO
Tables can be dropped by calling the dropTable function.
var params = {
name: ...,
ignore: ...,
done: ...,
fail: ...
};
var db = $.db("people", "", "People Database", 1024 * 1024, callback);
db.dropTable(params);
The name property of the object passed to the createTable function will be the name of the table that is dropped.
TODO
TODO