node-pg-pool icon indicating copy to clipboard operation
node-pg-pool copied to clipboard

Add connectionSetup as configuration option to prepare a client

Open bramkoot opened this issue 9 years ago • 7 comments

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)
  }
})

bramkoot avatar Jan 26 '17 16:01 bramkoot

Yeah i really dig this big time.

brianc avatar Mar 09 '17 20:03 brianc

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

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

brianc avatar Mar 09 '17 20:03 brianc

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'

bramkoot avatar May 04 '17 20:05 bramkoot

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

charmander avatar May 04 '17 22:05 charmander

@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.

brianc avatar May 05 '17 01:05 brianc

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

bramkoot avatar May 05 '17 08:05 bramkoot

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

seriouscoderone avatar Apr 11 '18 16:04 seriouscoderone