Skip to content

Commit

Permalink
Adding code for destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHeun committed Feb 9, 2024
1 parent 0ecd810 commit 55544d0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions R/destroy.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ pl_destroy <- function(conn,
}

if (drop_tables) {
# Remove all tables in the database
DBI::dbListTables(conn) |>
purrr::map(function(this_table_name) {
DBI::dbExecute(conn, paste0('DROP TABLE "', this_table_name, '" CASCADE;'))
})
table_names <- DBI::dbListTables(conn)
if (inherits(conn, "RPostgres") {
# Remove all tables in the database
table_names |>
purrr::map(function(this_table_name) {
DBI::dbExecute(conn, paste0('DROP TABLE "', this_table_name, '" CASCADE;'))
})
} else if (inherits(conn, "RSQLite"))
table_names |>
purrr::map(function(this_table_name) {
DBI::dbExecute(conn, paste0('DROP TABLE "', this_table_name, '" CASCADE;'))
})
}

return(invisible(TRUE))
}

0 comments on commit 55544d0

Please sign in to comment.