Skip to content

Commit

Permalink
Merge pull request #623 from cynkra/f-599-dm_from_src-pool-obj
Browse files Browse the repository at this point in the history
- `dm_from_src()` supports `pool::Pool` objects (#599, @moodymudskipper).
  • Loading branch information
krlmlr committed Sep 27, 2021
2 parents 39e45ca + 45c7330 commit 72d4c1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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")
})

0 comments on commit 72d4c1a

Please sign in to comment.