SQL à la speed

Meet AlaSQL, a speedy SQL database for JavaScript

Eirini-Eleni Papadopoulou
© Shutterstock / mystockdesigns

Hungry for some SQL à la speed? Time to meet AlaSQL, an open source SQL database for JavaScript built for speed and convenience. Let’s have a closer look.

Introducing a young interesting project, AlaSQL, an open source SQL database for JavaScript.

AlaSQL focuses on query speed and data source flexibility for both relational data and schemaless data. What’s more, it works in the web browser, Node.js, and mobile apps.

So what does AlaSQL bring to the ecosystem? Here are some of its most interesting characteristics:

  • Fast in-memory SQL data processing for BI and ERP applications on fat clients
  • Easy ETL and options for persistence by data import/manipulation/export of several formats

Let’s have a closer look at its main features and how you can give it a try.

The highlights

Here are some of the most interesting features of AlaSQL:

Traditional SQL – Use “good old” SQL on your data with multiple levels of: JOINVIEWGROUP BYUNIONPRIMARY KEYANYALLINROLLUP()CUBE()GROUPING SETS()CROSS APPLYOUTER APPLYWITH SELECT, and subqueries. See the extensive list here.

User-Defined Functions in your SQL – You can use all benefits of SQL and JavaScript together by defining your own custom functions.

Compiled statements and functions – See all the info on this feature in the wiki.

SELECT against your JavaScript data – Group your JavaScript array of objects by field and count number of records in each group.

JavaScript Sugar – AlaSQL extends “good old” SQL to make it closer to JavaScript. The “sugar” includes:

  • Write Json objects – {a:'1',b:@['1','2','3']}
  • Acesss object propertires – obj->property->subproperty
  • Access Ooject and arrays elements – obj->(a*1)
  • Access JavaScript functions – obj->valueOf()
  • Format query output with SELECT VALUE, ROW, COLUMN, MATRIX
  • ES5 multiline SQL with var SQL = function(){/*SELECT 'MY MULTILINE SQL'*/} and pass instead of SQL string (will not work if you compress your code)

Read and write Excel and raw data files – You can import from and export to CSV, TAB, TXT, and JSON files. File extensions can be omitted. Calls to files will always be asynchronous so multi-file queries should be chained.

Read SQLite database files – AlaSQL can read (but not write) SQLite data files using SQL.js library. sql.js calls will always be asynchronous.

AlaSQL works in the console – CLI – The node module ships with an alasql command-line tool.

Head over to the GitHub repo to check out all the detailed features and examples.

SEE ALSO: SQLDelight 1.0 arrives with a complete rework

Getting started

You can install AlaSQL by running:

npm install --save alasql      # node
bower install --save alasql    # bower
npm install -g alasql          # global installation for command line tools

For the browser, you need to include alasql.min.js.

See the ‘getting started‘ guide for all the relevant information.

Eirini-Eleni Papadopoulou
Eirini-Eleni Papadopoulou was the editor for Coming from an academic background in East Asian Studies, she decided that it was time to go back to her high-school hobby that was computer science and she dived into the development world. Other hobbies include esports and League of Legends, although she never managed to escape elo hell (yet), and she is a guest writer/analyst for competitive LoL at TGH.

Inline Feedbacks
View all comments