A DataSource implementation for DBI database connections (SQLite, PostgreSQL, MySQL, etc.). This class wraps a DBI connection and provides SQL query execution against a single table in the database.
Super class
DataSource -> DBISource
Methods
Inherited methods
DBISource$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
DBISource$get_schema()
Get schema information for the database table
DBISource$get_semantic_views_description()
Get information about semantic views (if any) for the system prompt.
DBISource$test_query()
Test a SQL query by fetching only one row
DBISource$cleanup()
No-op: the DBI connection is owned by the caller. Disconnect it
yourself with DBI::dbDisconnect() when your application shuts down.
Examples
# Connect to a database
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(con, "mtcars", mtcars)
# Create a DBI source
db_source <- DBISource$new(con, "mtcars")
# Get database type
db_source$get_db_type() # Returns "SQLite"
#> [1] "SQLite"
# Execute a query
result <- db_source$execute_query("SELECT * FROM mtcars WHERE mpg > 25")
# cleanup() is a no-op: you own `con`, so disconnect it yourself
db_source$cleanup()
DBI::dbDisconnect(con)
