Skip to content

Commit

Permalink
add option for local connection
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaust committed Oct 16, 2024
1 parent 3b886e4 commit 1d0b335
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions R/database.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 1d0b335

Please sign in to comment.