-
Notifications
You must be signed in to change notification settings - Fork 664
How to use SQL to query javascript objects
Mathias Rangel Wulff edited this page Jun 13, 2015
·
3 revisions
Source: StackOverflow.com
Is there a way to run an SQL query against javascript objects to find data within them? Specifically I'm looking for a way to query a few objects (each representing a table of data) and perform a join on them.
AlaSQL is a JavaScript SQL data manipulating library and supports SQL syntax.
This is an example:
var data = [{ dep: 'A', qt: 10, price: 5}, { dep: 'A', qt: 5, price: 2.30 },
{ dep: 'B', qt: 3, price: 2.20 }, { dep: 'C', qt: 1, price: 4 },
{ dep: 'C', qt: 4, price: 10 }];
var res = alasql('SELECT dep, SUM(qt) AS qt, SUM(qt*price) AS amt, \
FROM ? GROUP BY dep',[data]);
Try this example in jsFiddle.
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo