Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Mathias Rangel Wulff edited this pageJun 20, 2016 ·5 revisions

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


Bower

To use AlaSQL via bower install as normal

bower install alasql --save

Meteor

To use AlaSQL with Meteor import it from NPM by having the following in your code

import alasql from 'alasql';

Node.js

For Node (>= 0.10) install with npm

npm install alasql --save

NPMNPM

Requirealasql 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}]

Commandline

You can access AlaSQLfrom the comandline by installing from npm globally

npm install alasql -g

Now 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 100

See more examplesat the wiki

Other options

For debug

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>

In browser with AMD or UMD

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

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp