Hi,
I have a web application created using Express. I would like to know what the best practices are to use pg-promise regarding opening and closing connections in a request-response cycle.
Thanks.
You do not open connections, the library does it automatically.
When executing more than one query within a request-response cycle you should use tasks (or transactions when needed).
See:
Thank you. Does this also mean that I don’t need to close the connection because it will automagically close due timeout?
On 12 Mar 2017, at 13:26, Vitaly Tomilov notifications@github.com wrote:
You do not open connections, the library does it automatically.
When executing more than one query within a request-response cycle you should use tasks, or transactions when needed.
See: Tasks https://github.com/vitaly-t/pg-promise/wiki/Learn-by-Example#tasks.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub https://github.com/vitaly-t/pg-promise/issues/295#issuecomment-285941237, or mute the thread https://github.com/notifications/unsubscribe-auth/AFRMc2wWYdoLjUEjWlOg72EhtSJBIREZks5rk-SAgaJpZM4MahZw.
The library automatically releases connections back into the pool, those close after a non-use timeout.
You will only use pgp.end() when implementing a run-through module / program that once finished needs to exit the process immediately. Other than that, you never use it.
See examples