I want to encapsulate my SQL execution in the Postgress database. My initial desire is to call a method to execute a specific query and another method to execute a multi-query transaction.
exports.executaSQL = function (select, listaParametros){
client.connect(function (err) {
if (err) throw err;
client.query(select, listaParametros, function (err, result) {
if (err) throw err;
return result.rows;
client.end(function (err) {
if (err) throw err;
});
});
});
};
/**
var objetoListaSelect = [];
objetoListaSelect.push({
select : 'SELECT 1 WHERE ID=$1 AND ID=$2'
params : [1, 6]
});
objetoListaSelect.push({
select : 'SELECT 1 WHERE ID=$1 AND ID=$2'
params : [1, 6]
});
**/
exports.executaTransacao = function (objetoListaSelect){
};
I would like the second function runTransaction to execute in the order it was added to the array, remembering the asynchronous execution of the queries, what would be a good solution?
Thank you in advance!