javascript - return array from tedious -


can't return array. @ exit need each value separately insert database. maybe somewhere made mistake callback. code below.

function executetest(connection, callback) {      var results = [];      var request = new request(ted_select, function(error) {          if (error) {             return callback(error);         }         // pass results array on through callback         callback(null, results);     });      request.on("row", function(rowobject) {         // populate results array         results.push(rowobject);     });     connection.execsql(request); }  function test(callback) {     var connection = new connection(config);     connection.on('connect', function(err) {         if (err) {             console.log(err);         } else {             console.log('connect database');             executetest(connection, function(error, results) {                 // here results array first query                 console.log(results);             });             settimeout(function(){connection.close(console.log('disconnect database'));},10000);         }         callback(null, results);     }); }  var value = test(); console.log(value); 

thanks.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -