dbConnectDetails {CDMConnector} | R Documentation |
dbConnectDetails
returns an object that can be used to connect to a
database with dbConnect at some future point in execution. Functions that
need to create a new connection to a database with dbConnect
can accept a
dbConnectDetails
object as an argument and use it to create a new
connection.
dbConnectDetails(drv, ...)
drv |
A DBI driver (e.g. |
... |
DBI Driver parameters needed to create a connection using DBI::dbConnect() |
A dbConnectArgs object that can be passed to dbConnect
## Not run:
library(DBI)
connectionDetails <- dbConnectDetails(RPostgres::Postgres(),
dbname = "cdm",
host = "localhost",
user = "postgres",
password = Sys.getenv("password"))
selfContainedQuery <- function(dbConnectDetails) {
con <- dbConnect(connectionDetails)
on.exit(dbDisonnect(con))
dbGetQuery(con, "select count(*) as n from synthea1k.person")
}
selfContainedQuery(connectionDetails)
## End(Not run)