I'm trying to get a node-mysql connection query to work in series with the result of the original query. After all the setup is done, this is the problematic part. It seems that the connection has already ended. How can I ensure that the query in processRow gets executed in tandem with the result of the original?
function processRow(row, callback){
connection.query('INSERT INTO other_table VALUES (?)', row.id, function(err, rows, fields) {
if (err) throw err;
});
callback();
}
var query = connection.query('SELECT id from tbl limit 2');
query
.on('error', function(err){
throw err;
})
.on('fields', function(fields){
})
.on('result', function(row){
processRow(row, function(){
connection.resume();
});
})
.on('end', function(){
//
});
connection.end();