A DataSource implementation for lazy SQL tibbles connected to databases via
dbplyr::tbl_sql() or dplyr::sql().
querychat::DataSource -> querychat::DBISource -> TblSqlSource
table_nameName of the table to be used in SQL queries
new()Create a new TblSqlSource
TblSqlSource$new(tbl, table_name = missing_arg())tblA dbplyr::tbl_sql() (or SQL tibble via dplyr::tbl()).
table_nameName of the table in the database. Can be a character
string, or will be inferred from the tbl argument, if possible.
A new TblSqlSource object
get_db_type()Get the database type
TblSqlSource$get_db_type()A string describing the database type (e.g., "DuckDB", "SQLite")
get_schema()Get schema information about the table
TblSqlSource$get_schema(categorical_threshold = 20)categorical_thresholdMaximum number of unique values for a text column to be considered categorical
A string containing schema information formatted for LLM prompts
execute_query()Execute a SQL query and return results
TblSqlSource$execute_query(query)querySQL query string to execute
A data frame containing query results
test_query()Test a SQL query by fetching only one row
TblSqlSource$test_query(query, require_all_columns = FALSE)querySQL query string to test
require_all_columnsIf TRUE, validates that the result includes
all original table columns (default: FALSE)
A data frame containing one row of results (or empty if no matches)
prep_query()Prepare a generic SELECT * FROM ____ query to work with the SQL tibble
TblSqlSource$prep_query(query)querySQL query as a string
A complete SQL query string
get_data()Get the unfiltered data as a SQL tibble
TblSqlSource$get_data()A dbplyr::tbl_sql() containing the original, unfiltered data
cleanup()Clean up resources (close connections, etc.)
TblSqlSource$cleanup()NULL (invisibly)
clone()The objects of this class are cloneable with this method.
TblSqlSource$clone(deep = FALSE)deepWhether to make a deep clone.