Javascript pg库异步?

时间:2018-03-13 11:40:58

标签: javascript pg-node

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()?

提前感谢...

0 个答案:

没有答案