Expand description
Bounded-memory streaming reads — the native-cursor counterpart to
the eager Connection::query.
query materializes the whole result into a Vec<Row>, which is
fine for the CLI table view but unusable for an embedder ingesting a
multi-million-row table under a fixed memory budget. RowCursor
pulls rows from a native driver cursor one bounded batch at a
time, so peak resident memory is O(batch + cap) rather than
O(total rows).
Bounded-memory model. Every backend drives a row producer that is
back-pressured: the async network drivers (tokio-postgres
query_raw, mysql_async query_iter, tiberius QueryStream)
expose a native row stream that only fetches more from the server as
the consumer pulls; the synchronous drivers (rusqlite, ODPI-C
oracle) run their row-stepping loop on a spawn_blocking thread
that feeds a bounded tokio::sync::mpsc channel — the producer
blocks on blocking_send once cap rows are in flight, so at most
cap rows are ever buffered ahead of the consumer. Either way no
code path collects the full result.
Blocking model. RowCursor borrows its connection’s private
current-thread runtime; each next_batch /
Iterator::next call drives the producer with block_on, blocking
the calling thread until the next row(s) arrive. The same
current-thread reentrancy rule as Connection
applies — never pull from a cursor inside another block_on on the
same thread.
Size guards. Each decoded row is checked against the connection’s
per-cell / per-row SizeGuards before it is
retained, so a pathological cell fails fast with a structured error
rather than OOMing a streaming ingest.
Structs§
- RowCursor
- A streaming read handle over a native database cursor.
Constants§
- DEFAULT_
CURSOR_ CAPACITY - Default number of rows a streaming cursor keeps in flight between the
producer and the consumer. Caps the bounded channel for the
synchronous (
spawn_blocking) backends and the defaultnext_batchchunk; the async backends are additionally bounded by the driver’s own server-side fetch window.
Type Aliases§
- BoxRow
Stream - A boxed, backend-erased stream of decoded rows.