Opens a native DuckDB streaming result through the Rducks extension and
returns the rows in DuckDB-sized batches as data frames, instead of an eager
DBI::dbGetQuery() result. Each batch is materialized directly from DuckDB
vectors to R values on the recorded R thread. The stream uses the extension's
database-scoped connection, so
it cannot see caller-connection temporary tables or views.
Value
An object of class rducks_query_stream with $next_batch()
(returns the next data-frame batch, or NULL at end of stream),
$close(), $schema (column names and Rducks type tokens), and $token.
The stream closes on $close() or rducks_release(con).
Examples
# \donttest{
db <- duckdb::dbConnect(duckdb::duckdb(config = list(allow_unsigned_extensions = "true")))
rducks_enable(db, threads = "single")
stream <- rducks_query_stream(db, "SELECT i::INTEGER AS i FROM range(1, 6) t(i)")
stream$next_batch()
#> i
#> 1 1
#> 2 2
#> 3 3
#> 4 4
#> 5 5
stream$close()
rducks_release(db)
DBI::dbDisconnect(db, shutdown = TRUE)
# }