I'm having trouble trying to get the Postgres data using Pg-Promise using this previous Stackoverflow question: Get the result of postgres-query as variable in nodejs.
If I do this code, the webpage just keeps loading and hangs, finally spitting out an EJS error "row_result is not defined". I just want to store the SELECT query results in a variable so I can use it outside of the db.task block. Any suggestions?
var row_result = "";
db.task(function * (t) {
let a= yield t.query("SELECT * FROM public.applications;");
return {a};
})
.then(data => {
row_result = JSON.parse(JSON.stringify(a));
res.render('/applications', {row_result:row_result});
})
.catch(error => {
console.log('error');
})
.finally(() => {
pgp.end();
});
In addition, is there any way to do this?
var row_result = "";
db.task(function * (t) {
let a= yield t.query("SELECT * FROM public.applications;");
return {a};
})
.then(data => {
row_result = JSON.parse(JSON.stringify(a));
})
.catch(error => {
console.log('error');
})
.finally(() => {
pgp.end();
});
res.render('/applications', {row_result:row_result});