I would like to store result from mysql query in an array ( docAutocomplete) and after all the query completed I wanted to see the final array. I am using async series for this purpose. The issue is the array doesn't print anything as it looks like doesn't have any data at the function(err,results).
var mysql = require('mysql'),
async = require("async");
var connection = mysql.createConnection({
host: 'xx',
user: 'xx',
password: 'xx',
database: 'xx'
multipleStatements: true
});
var docAutocomplete = [];
async.series([
function(callback) {
connection.connect();
connection.query('select x from a; select b from a', function(err, rows, fields) {
if (err) throw err;
for (var i = 0; i < rows[0].length; i++) {
docAutocomplete.push({
" First Name": rows[0][i].x
})
}
for (var i; i < rows[1].length; i++) {
docAutocomplete.push({
"Last Name": rows[1][i].b
})
}
});
callback(null, 'one');
},
function(callback) {
connection.end();
callback(null, 'two');
}
],
function(err, results) {
console.log(results);
console.log(JSON.stringify(docAutocomplete));
});
Current output is something like below;
[ 'one', 'two' ]
[] // value of docAutocomplete array. Should have something here First Name and Last name
I am using a off canvas menu similar to the one on W3 Schools by having two functions called to toggle the menu on/off using onclick. I am wanting to add in a function to be able to close the menu by ...
I am using a off canvas menu similar to the one on W3 Schools by having two functions called to toggle the menu on/off using onclick. I am wanting to add in a function to be able to close the menu by ...
I have AWS Cognito installed for my Angular application, and I am trying to hook in the s3.putObject some how into the ng-file-upload Upload service. I want to use ng-file-upload's Upload.upload() ...
I have AWS Cognito installed for my Angular application, and I am trying to hook in the s3.putObject some how into the ng-file-upload Upload service. I want to use ng-file-upload's Upload.upload() ...
I want to know if it is more correct to use innerHTML: function createModal(){ modal = document.createElement('div'); modal.id = "modal"; modal.className = "modal"; modal.innerHTML = "<...
I want to know if it is more correct to use innerHTML: function createModal(){ modal = document.createElement('div'); modal.id = "modal"; modal.className = "modal"; modal.innerHTML = "<...
I have a working graph which displays some nodes & their attributes. Then I get a JSON with different data, where some nodes may already exist on my graph. How to combine both data sources, to ...
I have a working graph which displays some nodes & their attributes. Then I get a JSON with different data, where some nodes may already exist on my graph. How to combine both data sources, to ...