cached_connection {duckdbfs}R Documentation

create a cachable duckdb connection

Description

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.

Usage

cached_connection(dbdir = ":memory:", read_only = FALSE)

Arguments

dbdir

Location for database files. Should be a path to an existing directory in the file system. With the default, all data is kept in RAM

read_only

Set to TRUE for read-only operation

Details

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.

Value

a duckdb::duckdb() connection object

Examples


con <- cached_connection()
close_connection(con)


[Package duckdbfs version 0.0.4 Index]