I'm running NodeJS
with pg-promise
for accessing my PostgreSQL
.
This is my test, which fails with undefined
:
function a() {
pgPromise.one('SELECT 1')
.then(row => {
return row;
})
.catch(error => {
console.log(error);
});
}
console.log(a());
I asume it fails with undefined
because it's running asyncronized.
I've tried to optimize with:
async function a() {
var output = null;
await pgPromise.one('SELECT 1')
.then(row => {
output = row;
})
.catch(error => {
console.log(error);
});
return output;
}
console.log(a());
But that simply gives me:
[2018-09-13 08:37:09.521] [LOG] Promise { <pending> }