dbConnect,dbConnectDetails-method {CDMConnector} | R Documentation |
Create connection details, save them in an object, and use them to connect to a database using dbConnect later during program execution.
## S4 method for signature 'dbConnectDetails'
dbConnect(drv)
drv |
An dbConnectDetails object created by |
An S4 object that inherits from DBIConnection used to communicate with the database engine.
## 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)