Pg-promise: question about opening a connection and pgp.end();

Created on 12 Mar 2017  Â·  3Comments  Â·  Source: vitaly-t/pg-promise

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.

question

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alpertuna picture alpertuna  Â·  4Comments

realcarbonneau picture realcarbonneau  Â·  4Comments

calibermind picture calibermind  Â·  3Comments

hawkeye64 picture hawkeye64  Â·  4Comments

msjoshi picture msjoshi  Â·  4Comments