Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use node-postgres package pool vs client?

I searched a lot about this , I am using the pool but do not know what is the difference between both?

    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()
like image 535
mercury Avatar asked Aug 19 '26 18:08

mercury


1 Answers

From https://node-postgres.com/features/pooling/:

If you're working on a web application or other software which makes frequent queries you'll want to use a connection pool.

If on the other hand you're writing a script or tool that will have at most one open connection during its runtime, with only a single transaction (or only sequential transactions on the same connection), you can use a single Client.

like image 66
Bergi Avatar answered Aug 21 '26 15:08

Bergi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!