I want to perform database operations in node app. What I expect is to execute queries one after one i.e. sequentially as second query is dependent on prior operation. Currently, I am using async.series module to achieve the expected results but, when I write a nested query, queries are executed asynchronously. How can I eliminate this asynchronous behavior while executing nested queries? Following is my code.
async.series([
function(callback){
dbClient.query(select_show_query,function(err,result1){
callback(err,result1.rows);
}) //dbclient query end
},//function end
function(callback){
dbClient.query(select_show_person_query,function(err,result2){
callback(err,result2.rows);
}) //dbclient query end
},//function end
function(callback){
dbClient.query(select_show_role_query,function(err,result3){
callback(err,result3.rows);
}) //dbclient query end
},//function end
function(callback){
dbClient.query(select_show_episode_query,function(err,result4){
callback(err,result4.rows);
}) //dbclient query end
},//function end
function(callback){
dbClient.query(select_show_genre_query,function(err,result5){
callback(err,result5.rows);
}) //dbclient query end
},//function end
function(callback){
dbClient.query(select_profile_photo_query,function(err,result6){
callback(err,result6.rows);
}) //dbclient query end
}//function end
],function(err,results){
if(err){
res.json({"status": "failed", "message": err.message})
}
else{
res.send(JSON.stringify(results));
}
} //function end
); //async end