Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript libraries that allow for SQL-like queries on JSON data? [closed]

Say our JSON data comes from a single MySQL table:

someJSON =    [ { name: 'bill' , sex:'M', income:50000 },                 { name: 'sara' , sex:'F', income:100000 },                  ...                ]; 

And say the pseudo-code is:

"Get all the person objects of all sex:F of income > 60000`".

Are there any javascript libraries that would allow one to code such queries on this JSON data using a SQL or SQL-like syntax.

In case you are curious, some context:

I am making the front-end of a data analysis web service for my organization without knowing what the future backend will be. In the future they will migrate their data from MS Access tables to some-sort of MySQL-type database. Until then I am using static JSON files to start development and was thinking it may be helpful for them in the future to have my javascript queries appear as MySQL queries. (The current MS Access database is unreachable from the web.)

like image 330
b_dev Avatar asked Jan 18 '11 04:01

b_dev


1 Answers

You can try alasql.js. It is pure JavaScript client-side SQL-server, where you can do queries over JSON objects.

   // Fill table with data    var data = [ { name: 'bill' , sex:'M', income:50000 },                 { name: 'sara' , sex:'F', income:100000 }];     // Do the query    console.log(alasql("SELECT * FROM ? WHERE sex='F' AND income > 60000",[data])); 

Try this in Fiddle

like image 112
agershun Avatar answered Sep 21 '22 21:09

agershun