I have a module in a route that needs to return a json with the content of several queries made in the same module and some of these queries are made with data extracted from the first queries, my code is similar to the following, but the problem I have it at the time of extracting the data, neither with callback
nor with promise
I managed to extract sincrona
of the values of the queries to be able to return the json composed of the queries, in some sites they answer with what is impossible, I think I'm green and must be a bullshit, I do not think that in a module can not return a array/json/string
with a compound of several queries to database, please someone can help I've been several days and several methods and I can not get it to work in any way.
My objective in a rough way would be the following:
var sql_ejecutar ="select * from tabla_generica";
var json1= conexion.query(sql_ejecutar, function(err, results, fields)
{
//Contenido en results, devue
});
conexion.end();
var json2= conexion.query(sql_ejecutar, function(err, results, fields)
{
//Contenido en results, devue
});
conexion.end();
var json3= conexion.query(sql_ejecutar, function(err, results, fields)
{
//Contenido en results, devue
});
conexion.end();
var json_devolver[0]['json1']=json1;
var json_devolver[0]['json2']=json2;
var json_devolver[0]['json3']=json3;
res.json(json_devolver);
How to do it correctly within the same NodeJS module?