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()?
提前致谢...