Skip to content

Compile

Mathias Rangel Wulff edited this page Jun 12, 2015 · 6 revisions

Presompile SQL statements

alasql.compile() lets you precompile statements. It is a kind a "prepare" in other SQL databases.

To compile statement use:

   var stmt = alasql.compile(sql)

Then run the statement:

   stmt([parameters array] [, callback])

Here is the example how to calculate sum of numbers > 2 from [1,2,3,4,5]:

    var data = [{a:1},{a:2},{a:3},{a:4},{a:5}];

    // Compile
    var mysum = alasql.compile("SELECT VALUE SUM(a) FROM ? WHERE a > 2");

    // Run
    var res = mysum([data])

Try this example in jsFiddle

Clone this wiki locally