brianc / node-pg-pool

A connection pool for node-postgres
MIT License
180 stars 64 forks source link

Add connectionSetup as configuration option to prepare a client #43

Open bramkoot opened 7 years ago

bramkoot commented 7 years ago

I propose to add an option 'connectionSetup' to make it possible to do setup before a client is used. My own use-case is to set the search path to a certain schema.

This relates to an open issue at node-postgres about the same use case: https://github.com/brianc/node-postgres/issues/1123

I use node-postgres in combination with pg-async and with the adjustment you would be able to do something like this:

const connection = new PgAsync({
  connectionString, 
  connectionSetup: (client, cb) => {
    client.query('SET search_path TO users')
       .then(_args => {
         cb(null, client)
       }).catch(cb)
  }
})
brianc commented 7 years ago

Yeah i really dig this big time.

brianc commented 7 years ago

Sorry I just saw it! :p been buuuusy! (too busy!)

If you write some tests for this I can merge it no problemo.

bramkoot commented 7 years ago

I've added some simple tests which works fine, but Travis fails for older node versions with some odd errors. Any idea's what that could be?

node 0.10 / 0.12:

standard: Unexpected linter output:
TypeError: Failed to load plugin react: Object function Object() { [native code] } has no method 'assign'
charmander commented 7 years ago

The linter isn’t compatible with Node ≤0.12 anymore. (It would be nice if pg didn’t have to be either…)

brianc commented 7 years ago

@charmander - I agree. In 1 week I'll be leaving full time employment to do freelancing and more full-time node-postgres support. At that point we should have a discussion about dropping old versions, splitting out promises into a sub-module of sorts, and doing other backwards incompatible changes. I want 7.x and beyond to be valuable and shed a bit of the support for versions of node that are > 3 years old.

bramkoot commented 7 years ago

Sounds good @brianc! Let me know if you need any help with this PR.

seriouscoderone commented 6 years ago

@brianc Let's wrap this up. This would be useful.