jsql-sx Wiki
jsql-sx is a javascript API for simple SQL-like local data handling
Brought to you by:
portucalle
In JSQL-SX a table is created in the general form by:
// Get a handle on a database //
var db = jsql.DB.open(db_name);
// Create the table //
db.create(table_name,
[[column_name_1, data_type, constraint],
[column_name_2, data_type, constraint],
...
[column_name_n, data_type, constraint]]
);
The general form for a column definition is an array containing 3 elements:
Example:
// Get a handle on a database named 'mail' //
var db = jsql.DB.open("mail");
// Create a table named 'inbox' //
db.create("inbox",
[["id", "INTEGER", "PRIMARY KEY"],
["date", "TEXT", "NOT NULL"],
["from", "TEXT", "NOT NULL"],
["to", "TEXT", "NOT NULL"],
["msg", "TEXT", "NULL"],
["new", "BOOLEAN", "NOT NULL"]]
);
A data type is an attribute that specifies the type of data the values in a column are allowed to be.
In JSQL-SX, data types are much simpler than the ones specified by SQL.
| Data Type | Comments |
|---|---|
| INTEGER or INT |
|
| FLOAT |
|
| BOOLEAN or BOOL |
|
| TEXT |
|
Constraints are the rules enforced on data columns.
In JSQL-SX, only column-level constraints are available and, currently, only the Primary Key constraint has real effects.
| Constraint | Comments |
|---|---|
| NULL |
|
| NOT NULL |
|
| PRIMARY KEY |
|
| TEXT |
|