Learn R Programming

querychat (version 0.2.0)

TblSqlSource: Data Source: SQL Tibble

Description

A DataSource implementation for lazy SQL tibbles connected to databases via dbplyr::tbl_sql() or dplyr::sql().

Arguments

Super classes

querychat::DataSource -> querychat::DBISource -> TblSqlSource

Public fields

table_name

Name of the table to be used in SQL queries

Methods


Method new()

Create a new TblSqlSource

Usage

TblSqlSource$new(tbl, table_name = missing_arg())

Arguments

tbl

A dbplyr::tbl_sql() (or SQL tibble via dplyr::tbl()).

table_name

Name of the table in the database. Can be a character string, or will be inferred from the tbl argument, if possible.

Returns

A new TblSqlSource object


Method get_db_type()

Get the database type

Usage

TblSqlSource$get_db_type()

Returns

A string describing the database type (e.g., "DuckDB", "SQLite")


Method get_schema()

Get schema information about the table

Usage

TblSqlSource$get_schema(categorical_threshold = 20)

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


Method execute_query()

Execute a SQL query and return results

Usage

TblSqlSource$execute_query(query)

Arguments

query

SQL query string to execute

Returns

A data frame containing query results


Method test_query()

Test a SQL query by fetching only one row

Usage

TblSqlSource$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)


Method prep_query()

Prepare a generic SELECT * FROM ____ query to work with the SQL tibble

Usage

TblSqlSource$prep_query(query)

Arguments

query

SQL query as a string

Returns

A complete SQL query string


Method get_data()

Get the unfiltered data as a SQL tibble

Usage

TblSqlSource$get_data()

Returns

A dbplyr::tbl_sql() containing the original, unfiltered data


Method cleanup()

Clean up resources (close connections, etc.)

Usage

TblSqlSource$cleanup()

Returns

NULL (invisibly)


Method clone()

The objects of this class are cloneable with this method.

Usage

TblSqlSource$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.