diff --git a/NEWS.md b/NEWS.md index ccb06c4..f65caa1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# EHDEN HMB v2.3.1 + +* Added Redshift connectivity in function `cdmFromConAllDbs` +* Updated the `KeyringSetup.R` file to add two additional credentials: port and server + # EHDEN HMB v2.3.0 * Added function `cdmFromConAllDbs` to connect to different SQL servers with ODBC drivers diff --git a/analysis/private/_incidenceAnalysis.R b/analysis/private/_incidenceAnalysis.R index 253fb7c..d006b01 100644 --- a/analysis/private/_incidenceAnalysis.R +++ b/analysis/private/_incidenceAnalysis.R @@ -266,14 +266,36 @@ cdmFromConAllDbs <- function(executionSettings) { } - ## Postgre + ## PostgreSql if (executionSettings$dbms == "postgresql") { ## Connect to server con <- DBI::dbConnect( drv = RPostgres::Postgres(), - host = host, - port = 5441, + host = executionSettings$server, + port = executionSettings$port, + dbname = dbName, + user = executionSettings$user, + password = executionSettings$password + ) + + ## Connect to database + cdm <- cdm_from_con( + con = con, + cdm_schema = schemaName, + write_schema = writeSchemaName + ) + + } + + ## Redshift + if (executionSettings$dbms == "redshift") { + + ## Connect to server + con <- DBI::dbConnect( + drv = RPostgres::Redshift(), + host = executionSettings$server, + port = executionSettings$port, dbname = dbName, user = executionSettings$user, password = executionSettings$password diff --git a/analysis/private/_utilities.R b/analysis/private/_utilities.R index c85e1e3..2f6072d 100644 --- a/analysis/private/_utilities.R +++ b/analysis/private/_utilities.R @@ -168,3 +168,21 @@ zipResults <- function(database) { crayon::cyan(here::here(paste0(zipName, ".zip"))),bullet = "info", bullet_col = "blue") } + + +defaultCreds <- function() { + + creds <- c( + "dbms", # the database dialect + "user", # the user name for the db + "password", # the password for the db + "port", + "server", + "connectionString", # the connection string to access the db + "cdmDatabaseSchema", # the database + schema (or just schema) hosting the cdm + "vocabDatabaseSchema", # the database + schema (or just schema) hosting the vocabulary, usually same as cdm + "workDatabaseSchema" # the database + schema (or just schema) hosting the work or scratch + ) + + return(creds) +} diff --git a/extras/KeyringSetup.R b/extras/KeyringSetup.R index b0fde99..2df4d73 100644 --- a/extras/KeyringSetup.R +++ b/extras/KeyringSetup.R @@ -10,7 +10,7 @@ library(tidyverse, quietly = TRUE) library(Ulysses) library(keyring) - +source("analysis/private/_utilities.R") ## B. Set Parameters ------------ @@ -36,7 +36,7 @@ setStudyKeyring(keyringName = keyringName, keyringPassword = keyringPassword) ### Set credential keys in keyring -setMultipleCredentials(cred = defaultCredentials(), +setMultipleCredentials(cred = defaultCreds(), db = configBlock, keyringName = keyringName, keyringPassword = keyringPassword,