pub struct QueryStream { /* private fields */ }Expand description
A stream of rows backed by true PG-level chunked fetching.
Created by Pool::query_stream.
The PoolGuard is held until the stream is fully consumed or dropped.
Rows are fetched in chunks of 64 via Execute(max_rows=64).
§Usage
Use advance() + next_row()
for row-by-row iteration:
let mut stream = pool.query_stream(sql, hash, &[])?;
while stream.advance()? {
let row = stream.next_row().unwrap();
let id: i32 = row.get_i32(0).unwrap();
// decode before next advance() — row borrows from arena
}Implementations§
Source§impl QueryStream
impl QueryStream
Sourcepub fn next_row(&mut self) -> Option<Row<'_>>
pub fn next_row(&mut self) -> Option<Row<'_>>
Get the next row from the current in-memory chunk.
Returns None when the current chunk is exhausted. Call
fetch_next_chunk() to load more rows
from the server, or use advance() which
handles chunk management automatically.
Rows borrow from the arena, which is reset between chunks. Each row
must be fully decoded (into owned types) before calling next_row()
again. The generated code already does this — it decodes into owned
struct fields.
Sourcepub async fn advance(&mut self) -> Result<bool, BsqlError>
pub async fn advance(&mut self) -> Result<bool, BsqlError>
Ensure the current chunk has rows available for next_row().
If the current chunk is exhausted but more rows exist on the server,
fetches the next chunk. Returns true if rows are available (call
next_row() next), false if all rows have been consumed.
This is the complement to next_row(). Together they form
the primary iteration pattern:
while stream.advance()? {
let row = stream.next_row().unwrap();
let id: i32 = row.get_i32(0).unwrap();
// decode before next advance() — row borrows from arena
}Sourcepub fn has_more(&self) -> bool
pub fn has_more(&self) -> bool
Whether more rows might be available (either in the current chunk or from the server).
Sourcepub async fn fetch_next_chunk(&mut self) -> Result<bool, BsqlError>
pub async fn fetch_next_chunk(&mut self) -> Result<bool, BsqlError>
Fetch the next chunk from the server.
Returns true if a new chunk was fetched (call next_row() to iterate
it). Returns false if all rows have been consumed.
The arena is reset before fetching the new chunk, invalidating any
previous Row references. The generated code always decodes rows into
owned fields before calling this.
Sourcepub fn columns(&self) -> &[ColumnDesc]
pub fn columns(&self) -> &[ColumnDesc]
Column descriptors for the result set.