Skip to content
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

Usage of pool.getConnection() vs pool.query() #1668

Closed
ddluc opened this issue Mar 18, 2017 · 6 comments
Closed

Usage of pool.getConnection() vs pool.query() #1668

ddluc opened this issue Mar 18, 2017 · 6 comments
Labels

Comments

@ddluc
Copy link

ddluc commented Mar 18, 2017

I'm trying to understand the pros / cons of using pool.getConnection() over pool.query().

From Issue #1202 I gathered that pool.query is essentially a shortcut for pool.getConnection(), connection.query() and connection.release(). So it would appear advantageous to just query the pool directly in most cases. The only major scenario where using pool.getConnection() might be beneficial is if you needed to execute a series of queries at once.

@sidorares
Copy link
Member

yes, exactly what you explained yourself. getConnection if you need transactions or some state between queries

@sidorares
Copy link
Member

sidorares commented Mar 18, 2017

two calls to pool.query() likely will happen in two separate connections ( and in parallel )

@ddluc
Copy link
Author

ddluc commented Mar 18, 2017

Thanks for the timely response! What are your thoughts on adding that info to this section of the docs? (Unless I'm just missing it)

@sidorares
Copy link
Member

I think it would be helpful for many

@ddluc
Copy link
Author

ddluc commented Mar 18, 2017

OK great -- I'll create a pull request once I'm wrapped up with what I'm working on.

@borekb
Copy link
Contributor

borekb commented May 30, 2018

The info here is very useful, I've created a PR which tries to incorporate it into README: #2031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants