Suor/pg-bricks

Close all clients

Closed this issue · 5 comments

Right now its not possible to access the pg module (posgres driver) meaning it's not possible to end any of the created connections to the pg server.

This makes it very difficult to write integration tests.

Suor commented

I see how this can be generally useful, so I exposed a reference to pg as db.pg. I don't quite get your use case though, so it probably can be better fit in some more higher level way. Why do want to close connections explicitly? And what it has to do with integration tests?

I don't want to close them explicitly, but I do want a way to "destroy" the db instance and have it clean up all of its resources.

When writing a system integration test that is backed by a live database, it is common to use different databases for each suite. Therefore, you want to throw away your current connections and reconnect.

I hope that helps.

Suor commented

So, what you actually want is some .close() or .shutdown() method?

Exactly, I should of been more articulate in my use-case.

Suor commented

So to close all clients in all pools you can:

db.pg.end()

There is no simple way in node-postgres to close clients of particular pool, which db.close() supposed to do, so I leave this hanging for now. Corresponding node-postgres issue: brianc/node-postgres#867