const { Pool, Client } = require("pg");
const pool = new Pool({
user: "postgres",
host: "localhost",
database: "postgres",
password: ""
});
function one(){
pool.query(
"SELECT id, first_name as firstname, last_name as lastname FROM students_student",
(err, res) => {
let returnValue = JSON.stringify(res.rows);
console.log(returnValue)
return returnValue
}
)
}
var res = console.log(one())
console.log(res)
刚开始使用node和pg库...
我不明白为什么在上面代码末尾的console.log中未定义res(returnValue很好)。我应该如何调用函数one()?
提前感谢...