From 1d0b335a790c318c53edcbf4738356cb21d7071f Mon Sep 17 00:00:00 2001 From: Kiri Date: Wed, 16 Oct 2024 15:30:13 -0700 Subject: [PATCH] add option for local connection --- R/database.R | 74 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/R/database.R b/R/database.R index 4cbc47d8..66cb9dd8 100644 --- a/R/database.R +++ b/R/database.R @@ -6,37 +6,49 @@ #' @importFrom RPostgres Postgres #' #' @export -data_connect <- function() { - pool <- tryCatch( - { - dbPool( - drv = Postgres(), - dbname = "climr", - host = "146.190.244.244", - port = 5432, - user = "climr_client", - password = "PowerOfBEC2023" - ) - }, - error = function(e) { - tryCatch( - { - dbPool( - drv = Postgres(), - dbname = "climr", - host = "146.190.244.244", - port = 5432, - user = "climr_client", - password = "PowerOfBEC2023" - ) - }, - error = function(f) { - warning("Could not connect to database. Will try using cached data.") - NULL - } - ) - } - ) +data_connect <- function(local = FALSE) { + if(local){ + pool <- dbPool( + drv = Postgres(), + dbname = "climr", + host = "localhost", + port = 5432, + user = "postgres", + password = "climrserver" + ) + }else{ + pool <- tryCatch( + { + dbPool( + drv = Postgres(), + dbname = "climr", + host = "146.190.244.244", + port = 5432, + user = "climr_client", + password = "PowerOfBEC2023" + ) + }, + error = function(e) { + tryCatch( + { + dbPool( + drv = Postgres(), + dbname = "climr", + host = "146.190.244.244", + port = 5432, + user = "climr_client", + password = "PowerOfBEC2023" + ) + }, + error = function(f) { + warning("Could not connect to database. Will try using cached data.") + NULL + } + ) + } + ) + } + return(pool) }