ConnectorDBI | R Documentation |
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.
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.
connector::Connector
-> ConnectorDBI
conn
The DBI connection. Inherits from DBI::DBIConnector
new()
Initialize the connection
ConnectorDBI$new(drv, ..., extra_class = NULL)
drv
Driver object inheriting from DBI::DBIDriver.
...
Additional arguments passed to DBI::dbConnect()
.
extra_class
character Extra class to assign to the new connector.
disconnect_cnt()
Disconnect from the database. See also disconnect_cnt.
ConnectorDBI$disconnect_cnt()
invisible self
.
tbl_cnt()
Use dplyr verbs to interact with the remote database table. See also tbl_cnt.
ConnectorDBI$tbl_cnt(name, ...)
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.
A dplyr::tbl object.
clone()
The objects of this class are cloneable with this method.
ConnectorDBI$clone(deep = FALSE)
deep
Whether to make a deep clone.
# 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.