dbConnect,dbConnectDetails-method {CDMConnector}R Documentation

Connect to a database using stored connection details

Description

Create connection details, save them in an object, and use them to connect to a database using dbConnect later during program execution.

Usage

## S4 method for signature 'dbConnectDetails'
dbConnect(drv)

Arguments

drv

An dbConnectDetails object created by dbConnectDetails()

Value

An S4 object that inherits from DBIConnection used to communicate with the database engine.

Examples

## 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)


[Package CDMConnector version 0.4.1 Index]