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
Post a Comment