Skip to main content

QueryStream

Struct QueryStream 

Source
pub struct QueryStream { /* private fields */ }
Expand description

Streaming view of a query result.

Constructed by crate::Connection::query. Owns the underlying DynRowStream and lets callers observe schema metadata, drain the rows, or close the cursor explicitly.

The type is not marked #[non_exhaustive] because every field is private; the struct is only ever built through QueryStream::new (driver authors / test helpers) or returned from crate::Connection::query (consumers). Adding a field is non-breaking.

Implementations§

Source§

impl QueryStream

Source

pub fn new(inner: Box<dyn DynRowStream>) -> Self

Wrap an existing row stream. Used by the default Connection::query implementation and by driver authors that build a richer stream out-of-band.

Column metadata is read on-demand from DynRowStream::columns — the caller does not pass it in (review fixup M8: prevents the redundant column-vector clone the previous shape required).

Source

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

Column headers describing the shape of every row this stream will yield. Safe to call before the first Self::next_row — the headers are materialised eagerly by the driver as part of opening the cursor. Delegates to the wrapped DynRowStream::columns so the two views never disagree.

Source

pub const fn rows_yielded(&self) -> usize

Number of rows successfully yielded so far. Drives the TUI’s “streaming · N rows” header.

Source

pub fn elapsed(&self) -> Duration

Elapsed wall-clock time since the stream was opened. Drives the TUI’s live-elapsed indicator.

Source

pub async fn next_row(&mut self) -> Option<Result<Row>>

Advance the stream by one row.

Returns None once the underlying stream reports end-of-data or a previous call returned an error. The fused shape lets callers loop with while let Some(row) = s.next_row().await without worrying about double-polling.

Source

pub async fn collect_all(self) -> Result<QueryResult>

Drain the stream into a materialised QueryResult. Used by tests, the MCP query tool, and the export path when the caller genuinely needs the whole shape in memory before continuing.

elapsed_ms is filled from the wall-clock between Connection::query returning and the last row arriving — useful for “how long did the streamed query take” reporting without the caller wiring its own timer.

On error any rows already yielded are discarded; the caller gets the engine error verbatim. If partial materialisation matters, use Self::next_row in a loop and accumulate manually.

Source

pub async fn collect_with_limit( self, limit: usize, ) -> Result<(QueryResult, bool)>

Drain the stream into a materialised QueryResult but stop once limit rows have been accumulated. Subsequent rows produced by the engine are discarded and the cursor is closed — useful for the MCP tool’s hard row cap without reaching for take-style adapters.

truncated in the returned tuple is true when the engine had more rows to give. Callers should surface this to the agent so it knows the response is incomplete.

Source

pub async fn close(self) -> Result<()>

Explicitly close the stream. Equivalent to dropping it for any driver that wires its Drop impl to release the cursor, but close() is awaitable so callers can surface server-side release errors. Required by drivers that hold ephemeral server-side state (PG portals, ClickHouse HTTP body) where the async close round-trip must complete before the connection is returned to the pool.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more