ConnectorDBI: Connector for DBI databases

ConnectorDBIR Documentation

Connector for DBI databases

Description

Connector object for DBI connections. This object is used to interact with DBI compliant database backends. See the DBI package for which backends are supported.

Details

We recommend using the wrapper function connector_dbi() to simplify the process of creating an object of ConnectorDBI class. It provides a more intuitive and user-friendly approach to initialize the ConnectorFS class and its associated functionalities.

Upon garbage collection, the connection will try to disconnect from the database. But it is good practice to call disconnect_cnt when you are done with the connection.

Super class

connector::Connector -> ConnectorDBI

Active bindings

conn

The DBI connection. Inherits from DBI::DBIConnector

Methods

Public methods

Inherited methods

Method new()

Initialize the connection

Usage
ConnectorDBI$new(drv, ..., extra_class = NULL)
Arguments
drv

Driver object inheriting from DBI::DBIDriver.

...

Additional arguments passed to DBI::dbConnect().

extra_class

character Extra class to assign to the new connector.


Method disconnect_cnt()

Disconnect from the database. See also disconnect_cnt.

Usage
ConnectorDBI$disconnect_cnt()
Returns

invisible self.


Method tbl_cnt()

Use dplyr verbs to interact with the remote database table. See also tbl_cnt.

Usage
ConnectorDBI$tbl_cnt(name, ...)
Arguments
name

character Name of the content to read, write, or remove. Typically the table name.

...

Additional arguments passed to the method for the individual connector.

Returns

A dplyr::tbl object.


Method clone()

The objects of this class are cloneable with this method.

Usage
ConnectorDBI$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# Create DBI connector
cnt <- ConnectorDBI$new(RSQLite::SQLite(), ":memory:")
cnt

# You can do the same thing using wrapper function connector_dbi()
cnt <- connector_dbi(RSQLite::SQLite(), ":memory:")
cnt
# Write to the database
cnt$write_cnt(iris, "iris")

# Read from the database
cnt$read_cnt("iris") |>
  head()

# List available tables
cnt$list_content_cnt()

# Use the connector to run a query
cnt$conn

cnt$conn |>
  DBI::dbGetQuery("SELECT * FROM iris limit 5")

# Use dplyr verbs and collect data
cnt$tbl_cnt("iris") |>
  dplyr::filter(Sepal.Length > 7) |>
  dplyr::collect()

# Disconnect from the database
cnt$disconnect_cnt()


connector documentation built on June 8, 2025, 11:36 a.m.