R6 class for managing DuckDB connections and pinning lazy database tables.
Wraps a pins::board_folder() with a cached connection object stored as
"cachedConnection" for automatic reconnection.
See also
conn() S4 generic for dbData objects
Methods
Method new()
Create a new dbProject object.
Usage
dbProject$new(path, ...)Arguments
pathA character string specifying the folder path for pins.
...Additional arguments passed to
connections::connection_open()
Method get_board()
Return the pins::board_folder() object used by the project.
Returns
The pins::board_folder() object.
Method pin_write()
Write a lazy database tbl to the project.
Arguments
xA
dplyr::tblobject to be written to the board.nameA character string specifying the name of the pin.
Method pin_delete()
Delete a pin from the project.
Arguments
nameA character string specifying the name of the pin to delete.
...Additional arguments passed to
pins::pin_delete().
Method restore()
Restore all pins from the board manifest.
Details
Reads the board manifest and restores the cached connection and all pinned objects. The connection is restored internally, while other pinned objects are returned as a named list for the user to assign.
Examples
project_path <- tempfile("dbproject-")
proj <- dbProject$new(path = project_path)
proj$pin_write(data.frame(id = 1:3), "example")
restored <- proj$restore()
names(restored)
proj$disconnect()
unlink(project_path, recursive = TRUE)Method print()
Print summary information, including connection status, path, and board details.
Examples
## ------------------------------------------------
## Method `dbProject$restore`
## ------------------------------------------------
project_path <- tempfile("dbproject-")
proj <- dbProject$new(path = project_path)
#> Creating new version '20260602T145728Z-72241'
#> Writing to pin 'cachedConnection'
#> Manifest file written to root folder of board, as `_pins.yaml`
proj$pin_write(data.frame(id = 1:3), "example")
#> Guessing `type = 'rds'`
#> Creating new version '20260602T145728Z-de4f9'
#> Writing to pin 'example'
#> Manifest file written to root folder of board, as `_pins.yaml`
restored <- proj$restore()
#>
#> Attaching package: ‘connections’
#> The following objects are masked from ‘package:dbProject’:
#>
#> connection_pin_read, read_pin_conn, write_pin_conn
#> Loading required package: DBI
names(restored)
#> [1] "example"
proj$disconnect()
unlink(project_path, recursive = TRUE)