View source: R/cached_connection.R
cached_connection | R Documentation |
This function is primarily intended for internal use by other
duckdbfs
functions. However, it can be called directly by
the user whenever it is desirable to have direct access to the
connection object.
cached_connection(
dbdir = ":memory:",
read_only = FALSE,
bigint = "numeric",
config = list(temp_directory = tempfile()),
autoload_exts = getOption("duckdbfs_autoload_extensions", TRUE)
)
dbdir |
Location for database files. Should be a path to an existing
directory in the file system. With the default (or |
read_only |
Set to |
bigint |
How 64-bit integers should be returned. There are two options: |
config |
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. |
autoload_exts |
should we auto-load extensions? TRUE by default,
can be configured with |
When first called (by a user or internal function),
this function both creates a duckdb connection and places
that connection into a cache (duckdbfs_conn
option).
On subsequent calls, this function returns the cached connection,
rather than recreating a fresh connection.
This frees the user from the responsibility of managing a connection object, because functions needing access to the connection can use this to create or access the existing connection. At the close of the global environment, this function's finalizer should gracefully shutdown the connection before removing the cache.
By default, this function creates an in-memory connection. When reading from on-disk or remote files (parquet or csv), this option can still effectively support most operations on much-larger-than-RAM data. However, some operations require additional working space, so by default we set a temporary storage location in configuration as well.
a duckdb::duckdb()
connection object
con <- cached_connection()
close_connection(con)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.