Answer the question
In order to leave comments, you need to log in
How to get object from pool.query query (Node Js, PostgreSQL)?
You need to get an object for further use.
First I tried to do this:
const getUsers = async () => {
await pool.query('select * from users', (err, result) => {
if (err) {
console.log(err);
}
return result.rows;
});
}
const data = getUsers();
console.log(data);
let data = [];
getUsers().then((result) => {
data = result;
console.log(data);
});
Answer the question
In order to leave comments, you need to log in
const getUsers = async () => {
let real_result = await pool.query('select * from users', (err, result) => {
if (err) {
console.log(err);
}
return result.rows;
});
return real_result;
}
let data = [];
getUsers().then((result) => {
data = result;
console.log(data);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question