An abstract R6 class defining the interface that custom QueryChat data
sources must implement. This class should not be instantiated directly;
instead, use one of its concrete implementations like DataFrameSource or
DBISource.
Public fields
table_name
Name of the table to be used in SQL queries
Methods
DataSource$get_db_type()
Get the database type
Returns
A string describing the database type (e.g., "DuckDB", "SQLite")
DataSource$get_schema()
Get schema information about the table
Usage
DataSource$get_schema(categorical_threshold = 20, table_spec = NULL)
Arguments
categorical_threshold
Maximum number of unique values for a text
column to be considered categorical
Returns
A string containing schema information formatted for LLM prompts
DataSource$get_schema_result()
Usage
DataSource$get_schema_result(categorical_threshold = 20, table_spec = NULL)
DataSource$execute_query()
Execute a SQL query and return results
Usage
DataSource$execute_query(query)
Arguments
query
SQL query string to execute
Returns
A data frame containing query results
DataSource$test_query()
Test a SQL query by fetching only one row
Usage
DataSource$test_query(query, require_all_columns = FALSE)
Arguments
query
SQL query string to test
require_all_columns
If TRUE, validates that the result includes
all original table columns (default: FALSE)
Returns
A data frame containing one row of results (or empty if no
matches)
DataSource$get_data()
Get the unfiltered data as a data frame
Returns
A data frame containing all data from the table
DataSource$get_data_description()
Get a human-readable data description for the system prompt.
Subclasses may override this to provide metadata-derived descriptions
(e.g., pin title/description). The default returns an empty string.
Usage
DataSource$get_data_description()
Returns
A string, or empty string if no description is available.
DataSource$cleanup()
Release resources this data source created. Only resources querychat
opened itself are closed (for example the in-memory DuckDB connection a
DataFrameSource creates). Connections passed in by the caller are
never closed; their lifecycle stays with the caller.
DataSource$clone()
The objects of this class are cloneable with this method.
Usage
DataSource$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
MyDataSource <- R6::R6Class(
"MyDataSource",
inherit = DataSource,
public = list(
initialize = function(table_name) {
self$table_name <- table_name
}
# Implement abstract methods here...
)
)