W
W
wobemah2021-10-11 23:21:16
PostgreSQL
wobemah, 2021-10-11 23:21:16

What is the difference between Pool and Client constructors in NPM package pg?

What is the difference between the Pool and Client constructors in the NPM pg package?
Which one to use and why?

ps: this package is used (as I understand it) as an adapter for PostgreSQL.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladlen Hellsite, 2021-10-12
@wobemah

Client is one connection
Pool is a connection store that issues a free connection upon request, if there are no free ones, it waits until it is free and issues a free connection. Base connections are slow, but if we support many connections in advance, we don't waste time connecting. So Pool takes care of maintaining connections (handling closing connections, opening new connections and maintaining connections using ping).
If we are talking about an application, then Pool is the right choice .

R
romaro, 2021-10-17
@romaro

I will add that pools are well written on this page from the node-postgres documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question