db_query_source: Create a lazy DBI query source

View source: R/datatable-source-query.R

db_query_sourceR Documentation

Create a lazy DBI query source

Description

The source implements table_source() and fetches bounded pages for a query result. The built-in pager supports RSQLite only. Other DBI drivers can provide an adapter list with column_names(connection, query, params), row_count(connection, query, params), and get_rows(connection, query, params, start, count, columns) callbacks. This keeps dialect-specific pagination in the backend adapter rather than assuming all DBI drivers use the same SQL.

Usage

db_query_source(connection, query, params = NULL, adapter = NULL)

Arguments

connection

A db_connection() wrapper or open DBI connection. It remains owned by its caller; closing this source never disconnects it.

query

A single query that returns a result set.

params

Optional DBI parameter list passed to the query.

adapter

Optional backend adapter callbacks. NULL selects the built-in RSQLite pager when connection is an RSQLite connection.

Details

The built-in SQLite adapter wraps the query as a subquery, runs one cached ⁠COUNT(*)⁠, and adds bound LIMIT/OFFSET values to page requests. A single trailing semicolon is removed before wrapping. The query must produce one result set; arbitrary SQL statements are not parsed or rewritten. The row count can be expensive, but it is computed once at source creation and on explicit refresh, never on repaint.

The returned source is read-only. Sorting, filtering, and search are not pushed into the user query.

Value

An experimental table_source() accepted directly by data_table().


termr documentation built on Oct. 21, 2026, 5:13 p.m.