-
Notifications
You must be signed in to change notification settings - Fork 664
Api
Andrey Gershun edited this page May 26, 2015
·
8 revisions
- alasql()
- alasql.compile(sql) - Compile statements
alasql(‘CREATE DATABASE test01’);
alasql(‘USE test01’);
alasql(‘CREATE TABLE one (a INT)’);
alasql(‘INSERT INTO one VALUES (10)’):
var res = alasql(‘SELECT * FROM one’);
var data = [{a:1}, {a:2}, {a:3}];
alasql(‘SELECT * FROM ? WHERE a >= ?’, [data, 2]);
// or
var db = new alasql.Database();
db.exec(“select * from one”, function(data) {
console.log(data.length);
});
AlaSQL supports promises with alasql.promise(sql,params)
function. It returns standard A/+ promise:
alasql.promise('SELECT * FROM test')
}).then(function(res){
// Process data
}).catch(function(err){
// Process errors
});
See [alasql object](Alasql Object)
WebSQL
var db = new alasql.Database(‘mydb’);
db.exec(‘SELECT * FROM City”);
alasql.fn.Date = Date;
alasql(‘CREATE order ( orderno INT, orderdate Date)’);
NB. Classes are case-sensitive
Register class as alasql type
alasql.fn.Date = Date;
Use NEW
alasql(‘SELECT NEW Date(yr,mn-1,dy) FROM orderdates’)
See [JSON Objects](Json Objects)
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo