Skip to content

Commit

Permalink
Ensure database connections are clossed on exit, even if script fails
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmlft committed Aug 21, 2024
1 parent 65f9c85 commit 52d1e00
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev/omop_analyses/analyse_omop_cdm.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version <- Sys.getenv("TEST_DB_OMOP_VERSION")
con <- DBI::dbConnect(duckdb::duckdb(
dbdir = glue::glue("{dir}/{name}_{version}_1.0.duckdb")
))
withr::defer(DBI::dbDisconnect(con))

# Function to execute one or more SQL queries and clear results
create_results_tables <- function(con, sql) {
Expand Down
1 change: 1 addition & 0 deletions dev/test_db/setup_test_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ con <- DBI::dbConnect(
)
)
)
withr::defer(DBI::dbDisconnect(con))

# Use 'cdm_from_con' to load the dataset and verify integrity
CDMConnector::cdm_from_con(
Expand Down

0 comments on commit 52d1e00

Please sign in to comment.