Skip to content

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

Description

@dereksonderegger

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking change ☠️API change likely to affect existing codefeaturea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions