何时使用node-postgres包池与客户端?

Hos*_*ury 2 postgresql node.js express

我对此进行了很多搜索,我正在使用游泳池,但不知道两者之间有什么区别?

    const { Client } = require('pg')
const client = new Client()
await client.connect()
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].message) // Hello world!
await client.end()
Run Code Online (Sandbox Code Playgroud)

Ber*_*rgi 5

来自https://node-postgres.com/features/pooling/

如果您正在开发 Web 应用程序或其他需要频繁查询的软件,您将需要使用连接池。

另一方面,如果您正在编写一个脚本或工具,在其运行时最多有一个打开的连接,并且只有一个事务(或同一连接上只有顺序事务),那么您可以使用单个Client.