Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support 'Pool' objects in dm_from_src #623

Merged
merged 3 commits into from Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -57,6 +57,7 @@ Imports:
tidyselect (>= 1.0.1),
vctrs (>= 0.3.2)
Suggests:
pool,
brio,
covr,
crayon,
Expand Down
6 changes: 6 additions & 0 deletions R/dm-from-src.R
Expand Up @@ -52,6 +52,12 @@ dm_from_src <- function(src = NULL, table_names = NULL, learn_keys = NULL,
# FIXME: Check empty arguments and ellipsis
return(empty_dm())
}

if (inherits(src, "Pool")) {
src <- pool_src <- pool::poolCheckout(src)
on.exit(pool::poolReturn(pool_src))
}

# both DBI-Connection and {dplyr}-src object are accepted
src <- src_from_src_or_con(src)
con <- con_from_src_or_con(src)
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-pool-support.R
@@ -0,0 +1,7 @@
test_that("dm_from_src supports 'Pool'", {
# expect no error
conn <- pool::dbPool(RSQLite::SQLite(), "", timeout = 10)
DBI::dbWriteTable(conn, "mtcars", mtcars)
dm <- dm::dm_from_src(conn, learn_keys = FALSE)
expect_identical(names(dm), "mtcars")
})