Skip to content

Commit

Permalink
copy_to() should return pooled object (#166)
Browse files Browse the repository at this point in the history
And implement `sql_join_suffix()` to fix problem thus revealed. Fixes #165.
  • Loading branch information
hadley authored Feb 18, 2023
1 parent c6e2e4a commit a719f31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# pool (development version)

* `copy_to()` now returns a tbl that uses the Pool.

* Added missing method for `sql_join_suffix()` (#165).

# pool 1.0.0

## New features
Expand Down
27 changes: 16 additions & 11 deletions R/dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ copy_to.Pool <- function(dest,
...) {
stop_if_temporary(temporary)

db_con <- poolCheckout(dest)
on.exit(poolReturn(db_con))

dplyr::copy_to(
dest = db_con,
df = df,
name = name,
overwrite = overwrite,
temporary = temporary,
...
)
local({
db_con <- poolCheckout(dest)
on.exit(poolReturn(db_con))

dplyr::copy_to(
dest = db_con,
df = df,
name = name,
overwrite = overwrite,
temporary = temporary,
...
)
})

tbl.Pool(dest, name)
}

# Lazily registered wrapped functions ------------------------------------------
Expand All @@ -74,6 +78,7 @@ dbplyr_register_methods <- function() {
dbplyr_s3_register("db_connection_describe")
dbplyr_s3_register("db_sql_render")
dbplyr_s3_register("sql_translation")
dbplyr_s3_register("sql_join_suffix")
})
}

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-dbplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test_that("can copy and collect", {
temporary = FALSE,
indexes = list(c("x", "y"), "y")
)
expect_s3_class(dbplyr::remote_con(db), "Pool")
expect_equal(dplyr::collect(db), df)

# But copy_to must not be temporary
Expand Down

0 comments on commit a719f31

Please sign in to comment.