Skip to content

Commit

Permalink
Wrap more dbplyr generics (#175)
Browse files Browse the repository at this point in the history
Fixes #171. Fixes #172.

And wrap `sql_query_fields` to simplify `tbl.pool`
  • Loading branch information
hadley authored Jan 11, 2024
1 parent 8ce7c0b commit f1b6561
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pool (development version)

* Add wrappers for dbplyr generics `db_col_types()` (#171) and
`db_copy_to()` (#172).

* Pool no longer generates spurious messages about needing to use
`in_schema()` or avoiding the use of `ident_q()`.

Expand Down
10 changes: 3 additions & 7 deletions R/dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
#'
#' poolClose(pool)
tbl.Pool <- function(src, from, ..., vars = NULL) {
con <- poolCheckout(src)
on.exit(poolReturn(con))

if (is.null(vars)) {
vars <- dplyr::db_query_fields(con, from)
}

dbplyr::tbl_sql("Pool", dbplyr::src_dbi(src), from, ..., vars = vars)
}

Expand Down Expand Up @@ -93,10 +86,13 @@ dbplyr_register_methods <- function() {
dbplyr_s3_register("db_collect")
dbplyr_s3_register("db_compute")
dbplyr_s3_register("db_connection_describe")
dbplyr_s3_register("db_copy_to")
dbplyr_s3_register("db_col_types")
dbplyr_s3_register("db_sql_render")
dbplyr_s3_register("sql_translation")
dbplyr_s3_register("sql_join_suffix")
dbplyr_s3_register("sql_query_explain")
dbplyr_s3_register("sql_query_fields")
})
}

Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ test_that("can copy and collect", {

# But copy_to must not be temporary
expect_snapshot(dplyr::copy_to(pool, df), error = TRUE)

db2 <- dplyr::auto_copy(
db,
tibble::tibble(x = 11),
copy = TRUE,
temporary = FALSE
)
expect_s3_class(dbplyr::remote_con(db2), "Pool")
})

test_that("can use one-table verbs", {
Expand Down

0 comments on commit f1b6561

Please sign in to comment.