You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For instance, if I need to implement a connection pool within a package, how should I proceed?
Previously, I created pool::dbPool() in the .onLoad() function and closed it with reg.finalizer(), which worked well. However, adding more data sources would clutter the .onLoad() function. Also, how can I establish a connection to the database only when it's needed for the first time?
Furthermore, if I invoke the following function multiple times, will it create multiple connections in a single pool, or will it create multiple pools?
I think your initial idea makes the most sense to me (although I'd use .onUnload rather than reg.finalizer()). And I think if you set minSize = 0 then the pool will only create connections as you need them — the function you suggested will create multiple pools, which I doubt is what you want.
I'm not sure what your concern with creating multiple pools in .onLoad() is: you're going to have to put that code somewhere. If you're concerned with creating a bunch of pool objects, you might want to put them in a list.
Thank you! Here is my scenario: I have multiple data sources required by various packages, and I want to centralize the connection methods in a single auxiliary package. This would allow me to connect to any of the data sources by executing functions such as dbcons::db_a() or dbcons::db_b(). This led to my initial question.
Alternatively, if I could utilize pool within an environment in the auxiliary package, is this a better option?
For instance, if I need to implement a connection pool within a package, how should I proceed?
Previously, I created
pool::dbPool()
in the.onLoad()
function and closed it withreg.finalizer()
, which worked well. However, adding more data sources would clutter the.onLoad()
function. Also, how can I establish a connection to the database only when it's needed for the first time?Furthermore, if I invoke the following function multiple times, will it create multiple connections in a single pool, or will it create multiple pools?
What would be the best approach in this scenario, or is there an example package that addresses this?
The text was updated successfully, but these errors were encountered: