- Notifications
You must be signed in to change notification settings - Fork689
Install
For the browser: Includealasql.min.js and callalasql() with your SQL statements:
<scriptsrc="//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)");varres=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 injsFiddle
To use AlaSQL via bower install as normal
bower install alasql --saveTo 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 --saveRequirealasql and create a new database to start executing your SQL.
varalasql=require('alasql');vardb=newalasql.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 SQLdb.exec("INSERT INTO example1 VALUES (1,3)");varres=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 AlaSQLfrom the comandline by installing from npm globally
npm install alasql -gNow you can accessalasql 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 prependVALUE to theSELECT
? will be replaced with the corresponding n'th argument.
alasql "VALUE SELECT 20-?+?" 5 100See more examplesat the wiki
Copy following files fromdist catalog to your project
- dist/alasql.js
- dist/alasql.js.map
Include file: alasql.js or to the HTML page:
<scriptsrc="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){vartest1=[{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-2026,Andrey Gershun &Mathias Rangel Wulff
Please help improve the documentation by opening a PR on thewiki repo

