GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Return the client instance in the `connect()` method by franciscop · Pull Request #3564 · brianc/node-postgres

Conversation

@franciscop

@franciscop franciscop commented Nov 26, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Note: I open this PR as a conversation starter, I've explained my reasoning in a Redis Issue here. I'd be happy to open an issue instead, but I thought showing the code would be faster/easier.

I'd like to suggest returning the client instance in the .connect() method, so that we can create a client in a single step:

const client = await new Client().connect();

If this change is welcome, I'd be happy to add more things to this PR like testing, documentation, etc.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@franciscop
Return the client instance in the connect() method
b473733
@brianc

brianc commented Jan 19, 2026

Copy link
Copy Markdown
Owner

yeah that's a nice little API QOL improvement! Tests & docs & we're good to merge! Sorry for the delay!

franciscop reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franciscop

franciscop commented Jan 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I'll try to get it done over the weekend!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc

brianc commented Jan 20, 2026

Copy link
Copy Markdown
Owner

awesome! no rush...it's all appreciated. ❤️

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

franciscop and others added 6 commits January 24, 2026 15:51
@franciscop
Merge branch 'brianc:master' into patch-1
91ae7b7
@franciscop
Added one basic test
0994e87
@franciscop
Renamed
22aaa4d
@franciscop
Testing the result
70cdced
@franciscop
Added equality check
695d977
@franciscop
Simplified docs for connecting
2ac07ba
@franciscop

franciscop commented Jan 24, 2026

Copy link
Copy Markdown
Contributor Author

I think it's ready! I replaced the main docs bit for connect(), but please let me know if you prefer I add it as an "alternative" instead and keep that line like the original 🙇

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc

brianc commented Jan 24, 2026

Copy link
Copy Markdown
Owner

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franciscop
Added it to the native client as well
7a46bd1
@franciscop

franciscop commented Jan 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, fixed it. A couple of things I noticed:

  1. This test was repeated in the file I'm modifying, I'd assume on purpose?
suite.test('valid connection completes promise', () => {
  const client = new pg.Client()
  return client.connect().then(() => {
    return client.end().then(() => {})
  })
})
  1. I'm only modifying the await client.connect(), while leaving the callback-based client.connect(() => {}) as-is without the client parameter, I thought this would be okay since now most people use async/await but please let me know if you want me to pass the client param there as well.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc

brianc commented Jan 25, 2026

Copy link
Copy Markdown
Owner

2. I'm only modifying the await client.connect(), while leaving the callback-based client.connect(() => {}) as-is without the client parameter, I thought this would be okay since now most people use async/await but please let me know if you want me to pass the client param there as well.

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 [email protected] though last time I tried (several years ago) some folks got rather upset....so not sure yet. :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@franciscop
Added this to the callback
58fc0c7
@franciscop

franciscop commented Jan 25, 2026

Copy link
Copy Markdown
Contributor Author

Now that I have a better look, it seems in fact that .connect() with callback was already passing the client instance to the function:

        this._connectionCallback(null, this)

But the native client was not, fixed it:

-      cb()
+      cb(null, this)

I'm considering removing them in [email protected] though last time I tried (several years ago) some folks got rather upset....so not sure yet

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc

brianc commented Jan 27, 2026

Copy link
Copy Markdown
Owner

Hey thanks so much for the PR! Will release it soon. :) ❤️

franciscop reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc
brianc merged commit 57e93b5 into brianc:master Jan 27, 2026
7 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@franciscop
franciscop deleted the patch-1 branch January 27, 2026 23:48
@brianc brianc mentioned this pull request Jan 30, 2026
Always check if activeQuery is null before using it #3586
Merged
@sirkostya009 sirkostya009 mentioned this pull request Jan 30, 2026
Change return type of Client.connect in pg DefinitelyTyped/DefinitelyTyped#74427
Merged
8 tasks done
@dcaffull dcaffull mentioned this pull request Mar 19, 2026
Update @types/pg dependency in @prisma/adapter-pg to support [email protected]+ type changes prisma/orm#29356
Closed
@mfeltscher mfeltscher mentioned this pull request Apr 1, 2026
fix: pg returns Client instance on connect() neondatabase/serverless#199
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@franciscop @brianc
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.