query.on is not a function

前端 未结 3 1596
梦谈多话
梦谈多话 2021-02-13 11:48

I am trying to learn how to use javascript to connect to a postgresql database but when I try to log a query to the console using query.on(...), I get a type error that says \"q

3条回答
  •  野的像风
    2021-02-13 12:31

    query.on has been removed from node-pg 7.

    See https://node-postgres.com/guides/upgrading for how to properly handle rows.

    The usual way is to use promises or async/await (using promises in a clearer way):

    await client.connect();
    var res = await client.query("SELECT * FROM json_test");
    res.rows.forEach(row=>{
        console.log(row);
    });
    await client.end();
    

提交回复
热议问题