I know amazing right?
Alasql is able to act on json data to provide in browser (and serverside) some rather advanced SQL queries.
Of course this doesn’t stop one from using anonymous functions to perform basic mapreduce and finds on the results:
<script type="application/javascript" src="//unpkg.com/mustache@latest"></script>
<script type="application/javascript" src="//unpkg.com/alasql@latest"></script>
<script type="application/javascript">
// Fill table with data
const data = [
{ id: 1, name: 'bill', sex:'M', income:50000 },
{ id: 2, name: 'Jim', sex:'M', income:30000 },
{ id: 3, name: 'sara' , sex:'F', income:100000 }
];
const queryView = () => "<h3>Query Results</h3><ul id='result'><li>Name: {{name}}</li><li>Gender: {{sex}}</li></ul>",
nameView = () => "<h3>Users</h3><div id='users'></div>"
// Do the query
results = { users: alasql("SELECT * FROM ? WHERE sex='M' AND income < 60000", [data])};
// Insert into rendered html
document.querySelector("query").innerHTML = Mustache.to_html(queryView(),
results.users.find((user) => (user.income > 45000))
);
document.querySelector("names").innerHTML = Mustache.to_html(nameView());
// Insert into templated html
alasql('SELECT name INTO HTML("#users", {headers:true}) FROM ?', [data]);
</script>
Check out the live demo for yourselves.
Now, through in a little requirejs then one can stop needing frameworks and get back to actually making a website.