R/Driver.R
, R/dbConnect__duckdb_driver.R
, R/dbDisconnect__duckdb_connection.R
duckdb.Rd
duckdb()
creates or reuses a database instance.
duckdb_shutdown()
shuts down a database instance.
Return an adbcdrivermanager::adbc_driver()
for use with Arrow Database
Connectivity via the adbcdrivermanager package.
dbConnect()
connects to a database instance.
dbDisconnect()
closes a DuckDB database connection.
The associated DuckDB database instance is shut down automatically,
it is no longer necessary to set shutdown = TRUE
or to call duckdb_shutdown()
.
duckdb(
dbdir = DBDIR_MEMORY,
read_only = FALSE,
bigint = "numeric",
config = list(),
...,
environment_scan = FALSE
)
duckdb_shutdown(drv)
duckdb_adbc()
# S4 method for class 'duckdb_driver'
dbConnect(
drv,
dbdir = DBDIR_MEMORY,
...,
debug = getOption("duckdb.debug", FALSE),
read_only = FALSE,
timezone_out = "UTC",
tz_out_convert = c("with", "force"),
config = list(),
bigint = "numeric",
array = "none"
)
# S4 method for class 'duckdb_connection'
dbDisconnect(conn, ..., shutdown = TRUE)
Location for database files. Should be a path to an existing
directory in the file system. With the default (or ""
), all
data is kept in RAM.
Set to TRUE
for read-only operation.
For file-based databases, this is only applied when the database file is opened for the first time.
Subsequent connections (via the same drv
object or a drv
object pointing to the same path)
will silently ignore this flag.
How 64-bit integers should be returned. There are two options: "numeric"
and "integer64"
.
If "numeric"
is selected, bigint integers will be treated as double/numeric.
If "integer64"
is selected, bigint integers will be set to bit64 encoding.
Named list with DuckDB configuration flags, see https://duckdb.org/docs/configuration/overview#configuration-reference for the possible options. These flags are only applied when the database object is instantiated. Subsequent connections will silently ignore these flags.
Reserved for future extensions, must be empty.
Set to TRUE
to treat
data frames from the calling environment as tables.
If a database table with the same name exists, it takes precedence.
The default of this setting may change in a future version.
Object returned by duckdb()
Print additional debug information, such as queries.
The time zone returned to R, defaults to "UTC"
, which
is currently the only timezone supported by duckdb.
If you want to display datetime values in the local timezone,
set to Sys.timezone()
or ""
.
How to convert timestamp columns to the timezone specified
in timezone_out
. There are two options: "with"
, and "force"
. If "with"
is chosen, the timestamp will be returned as it would appear in the specified time zone.
If "force"
is chosen, the timestamp will have the same clock
time as the timestamp in the database, but with the new time zone.
How arrays should be returned. There are two options: "none"
and "matrix"
.
If "none"
is selected, arrays are not returned. Instead an error is generated.
If "matrix"
is selected, arrays are returned as a column matrix. Each array is one row in the matrix.
A duckdb_connection
object
Unused. The database instance is shut down automatically.
duckdb()
returns an object of class duckdb_driver.
dbDisconnect()
and duckdb_shutdown()
are called for their
side effect.
An object of class "adbc_driver"
dbConnect()
returns an object of class duckdb_connection.
library(adbcdrivermanager)
with_adbc(db <- adbc_database_init(duckdb_adbc()), {
as.data.frame(read_adbc(db, "SELECT 1 as one;"))
})
#> one
#> 1 1
drv <- duckdb()
con <- dbConnect(drv)
dbGetQuery(con, "SELECT 'Hello, world!'")
#> 'Hello, world!'
#> 1 Hello, world!
dbDisconnect(con)
duckdb_shutdown(drv)
# Shorter:
con <- dbConnect(duckdb())
dbGetQuery(con, "SELECT 'Hello, world!'")
#> 'Hello, world!'
#> 1 Hello, world!
dbDisconnect(con, shutdown = TRUE)