AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

Can I get an Array of Arrays instead of an Array of Objects? #637

Closed loque closed 8 years ago

loque commented 8 years ago

Is it possible to get an Array of Arrays from a query instead of an Array of Objects?

I mean, instead of this:

var result = alasql('SELECT field1, field2 FROM table_name');
// result = [{field1: "value1", field2: "value2"}, {field1: "value3", field2: "value4"}]

This:

var result = alasql('SELECT field1, field2 FROM table_name');
// result = [["value1", "value2"], ["value3", "value4"]]

I know I can do it myself afterwards, but maybe there is a way of telling alasql to do it internally so that the results are not iterated over again by me. If result has 300k rows * 10 fields this makes a difference.

mathiasrw commented 8 years ago

By prepending MATRIX OF before SELECT you will get what you are looking for.

var result = alasql('MATRIX OF SELECT field1, field2 FROM table_name');
// result = [["value1", "value2"], ["value3", "value4"]]

https://github.com/agershun/alasql/wiki/Matrix