Add connectionSetup as configuration option to prepare a client
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)
}
})
Yeah i really dig this big time.
Sorry I just saw it! :p been buuuusy! (too busy!)
If you write some tests for this I can merge it no problemo.
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'
The linter isn’t compatible with Node ≤0.12 anymore. (It would be nice if pg didn’t have to be either…)
@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.
Sounds good @brianc! Let me know if you need any help with this PR.
@brianc Let's wrap this up. This would be useful.