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

Connection originating from nycflights13_sqlite() cannot be disconnected from. #440

Closed
dereksonderegger opened this issue Apr 30, 2020 · 1 comment
Labels
breaking change ☠️ API change likely to affect existing code feature a feature request or enhancement
Milestone

Comments

@dereksonderegger
Copy link

While using the nycflights13_sqlite() function to create an example database for teaching, we are unable to use the standard DBI::dbDisconnect() function to close the connection. This is a problem when trying to teach students good behavior and to close their connections.

The root of the problem is the src_dbi() function call at the end of the copy_nycflights13() function. But given that src_dbi() is no longer recommended, and users should generate tables directly from the connection using tbl(), should the src_dbi() command still be there?

If you believe that nycflights13_sqlite() function shouldn't be changed (so as to avoid breaking other peoples' examples), could the documentation at least mention that this is an unusual case and the connection can't be closed?

library(dbplyr)

# Opening up a SQLite connection and copying the tables
# and then closing the connection works.
con <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:")
dplyr::copy_to(con, nycflights13::flights)
dplyr::copy_to(con, nycflights13::airlines)
DBI::dbDisconnect(con)


# But doing the same thing using the nycflights13_sqlite() 
# function does not work because there is no dbDisconnect
# overload function for a src_SQLiteConnection object.
con <- nycflights13_sqlite( )
#> Caching nycflights db at /var/folders/d1/drs_scp95wd_s6zsdksk312m0000gn/T//RtmpkDr7RR/nycflights13.sqlite
#> Creating table: airlines
#> Creating table: airports
#> Creating table: flights
#> Creating table: planes
#> Creating table: weather
DBI::dbDisconnect(con)
#> Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'dbDisconnect' for signature '"src_SQLiteConnection"'

Created on 2020-04-30 by the reprex package (v0.3.0)

@hadley
Copy link
Member

hadley commented May 15, 2020

I think I looked at returning the connection rather than the src, but it broke some downstream packages. But I think that's a good thing to do, the next time we do a bigger release.

@hadley hadley added breaking change ☠️ API change likely to affect existing code feature a feature request or enhancement labels May 15, 2020
@hadley hadley added this to the 2.0.0 milestone May 15, 2020
@hadley hadley closed this as completed in 56d08a3 Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change ☠️ API change likely to affect existing code feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants