Alexander Ivanov Alexander Ivanov - 7 months ago 75
Javascript Question

How to set the alasql output as Array

I need to set the alasql output as Array. Is it possible?

I don't find any method for this



var pre = document.getElementById('pre');
var keys = Object.keys(alasql).map(function(e) {
return [e];
});
var qLikes = alasql('SELECT * FROM ? WHERE [0] LIKE "%uery%"', [keys]);
pre.innerHTML = JSON.stringify(qLikes, null, ' ');
var pre = document.getElementById('pre');

<script src="https://cdn.rawgit.com/agershun/alasql/develop/dist/alasql.min.js"></script>
<pre id="pre"></pre>




Answer

With AlaSQL you can prepend COLUMN OF to your SQL to get out an array of values representing the first column in your dataset.

var qLikes = alasql('COLUMN OF SELECT * FROM ? WHERE [0] LIKE "%uery%"', [keys]);

Example

var pre = document.getElementById('pre');
var keys = Object.keys(alasql).map(function(e) {
  return [e];
});
var qLikes = alasql('COLUMN OF SELECT * FROM ? WHERE [0] LIKE "%uery%"', [keys]);
pre.innerHTML = JSON.stringify(qLikes, null, ' ');
var pre = document.getElementById('pre');
<script src="https://cdn.rawgit.com/agershun/alasql/develop/dist/alasql.min.js"></script>
<pre id="pre"></pre>

Comments