- 
                Notifications
    You must be signed in to change notification settings 
- Fork 689
Install
For the browser: Include alasql.min.js and call
alasql() with your SQL statements:
<script src="//cdn.jsdelivr.net/alasql/0.2/alasql.min.js"></script> 
<script>
    
	alasql("CREATE TABLE cities (city string, population number)");
        
	alasql("INSERT INTO cities VALUES ('Rome',2863223), ('Paris',2249975), ('Berlin',3517424),  ('Madrid',3041579)");
        
	var res = alasql("SELECT * FROM cities WHERE population < 3500000 ORDER BY population DESC");
   
	// res now contains this array of object:
	// [{"city":"Madrid","population":3041579},{"city":"Rome","population":2863223},{"city":"Paris","population":2249975}] 	
   
</script>Play with this example in jsFiddle
To use AlaSQL via bower install as normal
bower install alasql --save
To use AlaSQL with Meteor import it from NPM by having the following in your code
import alasql from 'alasql';
For Node (>= 0.10) install with npm
npm install alasql --save
Require alasql and create a new database to start executing your SQL.
var alasql = require('alasql');
var db = new alasql.Database();
db.exec("CREATE TABLE example (a INT, b INT)");
// You can insert data directly from javascript object...
db.tables.example1.data = [ 
    {a:5,b:6},
    {a:3,b:4}
];
// ...or you can insert data with normal SQL 
db.exec("INSERT INTO example1 VALUES (1,3)");
var res = db.exec("SELECT * FROM example1 ORDER BY b DESC");
// res now contains this array of objects:
// [{a:1,b:3},{a:3,b:4},{a:3,b:4}]You can access AlaSQL from the comandline by installing from npm globally
npm install alasql -g
Now you can access alasql via the commandline
> alasql "SELECT * INTO json('my.json') from xlsx('cities.xlsx',{headers:true}) WHERE population > 20000000"
To get get value instead of a JSON you can prepend VALUE to the SELECT
? will be replaced with the corresponding n'th argument.
alasql "VALUE SELECT 20-?+?" 5 100
See more examples at the wiki
Copy following files from dist catalog to your project
- dist/alasql.js
- dist/alasql.js.map
Include file: alasql.js or to the HTML 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>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.log( alasql('SELECT a, b*c AS bc FROM ? AS t',[test1]) );
    });© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo

