Skip to content

installation

agershun edited this page Dec 28, 2014 · 11 revisions

Installation

In browser

  1. For production: copy file from dist catalog to your project
  • dist/alasql.min.js
  1. For debug: copy two files to your porject:
  • dist/alasql.js
  • dist/alasql.js.map

Include file: alasql.js to the page.

  <script src="alasql.js"></script>  
  <script>
    alasql("CREATE TABLE test (language INT, hello STRING)");
    alasql("INSERT INTO test VALUES (1,'Hello!')");
    alasql("INSERT INTO test VALUES (2,'Aloha!')");
    alasql("INSERT INTO test VALUES (3,'Bonjour!')");
    console.table(alasql("SELECT * FROM test WHERE language > 1"));
  </script>

In browser AMD

You can use alasql.js with define()/require() functions in browser as well, because it supports AMD and UMD:

    require(['../../alasql.js'], function(alasql) {
        var test1 = [{a:1,b:2,c:3},{a:4,b:5,c:6},{a:7,b:8,c:9}];
        console.table(alasql('SELECT a, b*c AS bc FROM ? AS t',[test1]));
    });

Like in this sample you do not need to CREATE TABLE and INSERTS if you do not need constraints functionality.

In Node.js

Use the following command for installation:

    npm install alasql

Then require alasql.js file:

    var alasql = require('alasql');

    var db = new alasql.Database();
    
    db.exec("CREATE TABLE test (one INT, two INT)");
    db.tables.test.data = [   // You can mix SQL and JavaScript
        {one:3,two:4},
        {one:5,two:6},
    ];
    var res = db.exec("SELECT * FROM test ORDER BY two DESC");
    console.log(res[0].one);
Clone this wiki locally