Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addressing #227 #224 #22 #154 and #137
This is bulk of the pool refactor. It is still a work in progress. The old API will remain intact but officially deprecated. The new api is as follows:
The api also allows you to force the pool to destroy and remove a client by passing an instance of
Error
(or anything truthy, actually) to thedone()
callback - I modeled this off of the async testing api in https://github.com/visionmedia/mochaThere are a few edge cases I tried to test more closely as well, including the following: note: never do this IRL
When a client emits an error in the background the root
pg
object will emit the error and more importantly the client will be destroyed and removed from the pool. The rootpg
object listens to the pool error and re-emits it, so you don't have to handle the error on a pool by pool basis. This should cover cases where postgres closes or fails in the background, all the clients will disconnect with errors and be removed from the pool. There is still work to do with failover & heartbeats and stuff however.I've exposed the entire pool area hanging off of the root
pg
object aspg.pools
. They are referenced by the JSON.stringify(connectionstring/connectionparameters/{}) so...this:All of the pools are exposed at
pg.pools.all
in a hash. This will allow you to use theacquire
andrelease
methods directly if thepg.connect
method doesn't suit your needs, supply a completely custom pool implementation, or do other helpful things like shutdown/destroy a particular pool. Ideally another module should be use for pooling, but at the very least this fixes the build in pool to not completely break and "leak" in strange gotcha scenarios.I'm looking for feedback & collaboration on this, so don't be shy!