-
Hi, in the past I used node-postgres and there I had to choose between client and pool. In postgresjs there is no such a thing, am I right or am I missing something? I am little confused tbh. Is establishing connection (like below) only needed and it could be used either for transactions and normal queries?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Simplicity can indeed be confusing when coming back to it 🤣 Postgres.js has a default max of 10 connections, but if you want a single one, just set max: 1 Transactions are run using sql.begin, and will block a connection while running, but you don't need to do anything specific yourself. You can also use sql.reserve if you explicitly need to have access to a single connection from the pool for a short period, but this is not something you usually need unless you have a special case. Connections are handled lazily, and with the best defaults, so a connection is not made until you make a query, and they are cycled and closed if idle per the defaults. If you think something is lacking in the docs, you're more than welcome to create a PR where we can work on getting it added / improved 😉 |
Beta Was this translation helpful? Give feedback.
Simplicity can indeed be confusing when coming back to it 🤣 Postgres.js has a default max of 10 connections, but if you want a single one, just set max: 1
Transactions are run using sql.begin, and will block a connection while running, but you don't need to do anything specific yourself. You can also use sql.reserve if you explicitly need to have access to a single connection from the pool for a short period, but this is not something you usually need unless you have a special case.
Connections are handled lazily, and with the best defaults, so a connection is not made until you make a query, and they are cycled and closed if idle per the defaults.
If you think something is lacking in the…