-
Notifications
You must be signed in to change notification settings - Fork 665
Alasql Object
agershun edited this page Dec 28, 2014
·
5 revisions
- alasql(sql,params,callback) – execute SQL
- alasql(data) - starting poit for [fluent interface](Fluent Interface)
- alasql.exec(sql,params,callback) – execute SQL
- alasql.parse(sql) – parse to AST (abstract syntax tree)
- ast.compile(databaseid) – compile statement and cache it in database cache
- alasql.exec(sql) – execute statement
- alasql.use(databaseid) – [use database](Use Database)
- alasql.pretty(sql) – pretty SQL output in HTML and TXT
- alasql.options - options
alasql(sql,[params],[callback])
sql – one or some SQL-statements separated by ‘;’ If one statement – alasql() returns one value
USE test12 => 1
SELECT * FROM one => [{a:1}, {a:2}]
If some statements – alasql() returns array of values, one for each statement
USE test12; SELECT * FROM one => [1,[{a:1}, {a:2}]]
params – an array of parameters of SQL statement You can use ? in SQL statement
alasql(‘SELECT a FROM ? WHERE b = ?’,[[{a:1,b:1}, {a:2,b:2}],2])
callback – a callback function
- Without callback alasql() runs synchroniously
- With callback alasql() runs asynchroniously with callbacks
See Sync and Async.
alasql is a main object and function of Alasql library. It can be used in some different ways:
<script src="alasql.js"></script>
<script>
alasql('create table capitals (country string, city string, population int)');
alasql('insert into capitals values ("USA", "Washington, D.C.", 646449)');
alasql('insert into capitals values ("France", "Paris", 2211000)');
alasql('insert into capitals values ("Russia", "Moscow", 11500000)');
alasql('insert into capitals values ("Mexica", "Mexico City", 8851000)');
alasql.log('select city,population from capitals order by population desc');
</string>
- Execute SQL statement or set of statements:
alasql(sql-statement)
- Class for a number functions:
- alasql.exec(sql, params, callback) - execute SQL statement
- alasql.value(sql, params, callback) - execute SQL statement but return only one value
- alasql.log(sql, params) - execute SQL statement and log the results to console or into HTML tag
- Class for options:
- alasql.options.logtarget - target for alasql.log() functions. Values can be "console" or HTML tag
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo