dbConnectDetails {CDMConnector}R Documentation

Save database connection information in an object

Description

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.

Usage

dbConnectDetails(drv, ...)

Arguments

drv

A DBI driver (e.g. RPostgres::Postgres())

...

DBI Driver parameters needed to create a connection using DBI::dbConnect()

Value

A dbConnectArgs object that can be passed to dbConnect

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]