Skip to content

Docs: use try/finally to always release the client #130

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

Merged
merged 2 commits into from
Apr 30, 2022
Merged

Docs: use try/finally to always release the client #130

merged 2 commits into from
Apr 30, 2022

Conversation

stefee
Copy link
Contributor

@stefee stefee commented Apr 30, 2022

Use try/finally to always release the client on error before handling

Refs: https://node-postgres.com/features/pooling#examples

// async/await - check out a client
;(async () => {
  const client = await pool.connect()
  try {
    const res = await client.query('SELECT * FROM users WHERE id = $1', [1])
    console.log(res.rows[0])
  } finally {
    // Make sure to release the client before any error handling,
    // just in case the error handling itself throws an error.
    client.release()
  }
})().catch(err => console.log(err.stack))

Checklist

Use try/finally to always release the client on error before handling

Refs: https://node-postgres.com/features/pooling#examples
@stefee stefee changed the title Update README.md Docs: use try/finally to always release the client Apr 30, 2022
@stefee stefee requested a review from Fdawgs April 30, 2022 13:41
Copy link
Member

@Fdawgs Fdawgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 7638230 into fastify:master Apr 30, 2022
@stefee stefee deleted the readme-patch1 branch April 30, 2022 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants