Skip to main content

QueryStream

Struct QueryStream 

Source
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

Source

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.

Source

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
}
Source

pub fn has_more(&self) -> bool

Whether more rows might be available (either in the current chunk or from the server).

Source

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.

Source

pub fn remaining(&self) -> usize

Number of remaining rows in the current chunk.

Source

pub fn columns(&self) -> &[ColumnDesc]

Column descriptors for the result set.

Trait Implementations§

Source§

impl Drop for QueryStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.