A DataSource implementation for DBI database connections (SQLite, PostgreSQL, MySQL, etc.).
Details
This class wraps a DBI connection and provides SQL query execution against a specified table in the database.
Super class
querychat::DataSource -> DBISource
Methods
Method new()
Create a new DBISource
Usage
DBISource$new(conn, table_name)Arguments
connA DBI connection object
table_nameName of the table in the database. Can be a character string or a
DBI::Id()object for tables in catalogs/schemas
Method get_schema()
Get schema information for the database table
Examples
if (FALSE) { # \dontrun{
# Connect to a database
conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(conn, "mtcars", mtcars)
# Create a DBI source
db_source <- DBISource$new(conn, "mtcars")
# Get database type
db_source$get_db_type() # Returns "SQLite"
# Execute a query
result <- db_source$execute_query("SELECT * FROM mtcars WHERE mpg > 25")
# Note: cleanup() will disconnect the connection
# If you want to keep the connection open, don't call cleanup()
} # }
## ------------------------------------------------
## Method `DBISource$new`
## ------------------------------------------------
if (FALSE) { # \dontrun{
conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(conn, "iris", iris)
source <- DBISource$new(conn, "iris")
} # }
