duckdb-r icon indicating copy to clipboard operation
duckdb-r copied to clipboard

Simplify `dbdir` entrypoint

Open JosiahParry opened this issue 9 months ago • 0 comments

At present, there are two places where the database directory can be specified for a DuckDB database instance. Either in the driver or in the connection functions respectively.

By having two places to specify the dbdir argument it is a bit confusing to know which is the preference. Then, there is a possible point of confusion where a database path may be specified in the driver but another in the connection function. And when this happens the path specified in dbConnect() silently takes precedence.

My personal preference would be that there is only one place to specify the path (it feels best to be in the driver, imo). Otherwise, there should be an error or a warning when setting dbir in dbConnect() when one is already provided by duckdb()

library(duckdb)

dbConnect(duckdb("mydb.duckdb"))
#> <duckdb_connection 76150 driver=<duckdb_driver dbdir='/reprex-7acf7dd015ed-sappy-tern/mydb.duckdb' read_only=FALSE bigint=numeric>>

dbConnect(duckdb(), "mydb.duckdb")
#> <duckdb_connection 8e300 driver=<duckdb_driver dbdir='/reprex-7acf7dd015ed-sappy-tern/mydb.duckdb' read_only=FALSE bigint=numeric>>

dbConnect(duckdb("a-different.duckdb"), "mydb.duckdb")
#> <duckdb_connection 3c7a0 driver=<duckdb_driver dbdir='/reprex-7acf7dd015ed-sappy-tern/mydb.duckdb' read_only=FALSE bigint=numeric>>

Created on 2024-05-24 with reprex v2.1.0

JosiahParry avatar May 25 '24 01:05 JosiahParry