Looking for some best practices using the pool
package to connect to a database and get data using dbGetQuery
.
I've been using something like this:
pool <- pool::dbPool(
drv = drv,
url = "url",
user = "username",
password = "password"
)
onStop(function() {
poolClose(pool)
})
conn <- poolCheckout(pool)
data_from_table <- dbGetQuery(conn,
"
select * from table
"
)
poolReturn(conn)
Is there a better way? Am I using pool
correctly and to its full potential? Am I safely creating and closing connections?
Thanks!