-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Return the client instance in the connect() method
#3564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
yeah that's a nice little API QOL improvement! Tests & docs & we're good to merge! Sorry for the delay! |
|
Thanks! I'll try to get it done over the weekend! |
|
awesome! no rush...it's all appreciated. ❤️ |
|
I think it's ready! I replaced the main docs bit for |
|
Thanks @franciscop! One thing: can you change the native client as well to do the same behavior? The tests are currently failing now due to the difference. |
|
Thanks, fixed it. A couple of things I noticed:
suite.test('valid connection completes promise', () => {
const client = new pg.Client()
return client.connect().then(() => {
return client.end().then(() => {})
})
})
|
I think for the pricipal of least surprise, it would probably be better to pass it to the callback. But yeah...I don't think its common to use the callback APIs anymore. I'm considering removing them in |
|
Now that I have a better look, it seems in fact that this._connectionCallback(null, this)But the native client was not, fixed it: - cb()
+ cb(null, this)
I hear you, in my bubble it seems like long ago that people used callbacks instead of promises, but I've never maintained such a popular project like this so I don't know about the people using it too well. |
I'd like to suggest returning the client instance in the
.connect()method, so that we can create a client in a single step:If this change is welcome, I'd be happy to add more things to this PR like testing, documentation, etc.