pub struct BlobStream<'a, S: ConnectionState = Ready> { /* private fields */ }Expand description
A stream of rows whose trailing MAX column is read incrementally from the
socket. See the module docs. Obtain one from
Client::query_stream_blob.
Implementations§
Source§impl<'a, S: ConnectionState> BlobStream<'a, S>
impl<'a, S: ConnectionState> BlobStream<'a, S>
Sourcepub fn columns(&self) -> &[Column]
pub fn columns(&self) -> &[Column]
The leading (scalar) columns of the result set — everything before the trailing MAX column(s).
Sourcepub fn blob_columns(&self) -> &[Column]
pub fn blob_columns(&self) -> &[Column]
The trailing MAX (blob) columns of the result set, in wire order.
For a query_stream_blob stream this
is a single column; for
query_stream_rows it is the run of
trailing MAX columns, in the order next_blob visits
them.
Sourcepub fn current_blob_column(&self) -> Option<&Column>
pub fn current_blob_column(&self) -> Option<&Column>
The column metadata of the currently positioned blob, or None before
the first blob of a row is positioned (or after the row is exhausted).
Sourcepub async fn next(&mut self) -> Result<Option<Row>>
pub async fn next(&mut self) -> Result<Option<Row>>
Advance to the next row, returning its scalar columns.
Auto-drains any unread trailing blob(s) of the previous row, so the wire
stays aligned. Returns Ok(None) at end of stream (connection clean).
Sourcepub async fn next_blob(&mut self) -> Result<bool>
pub async fn next_blob(&mut self) -> Result<bool>
Advance to the next trailing MAX column of the current row, returning
true while one is positioned and false once the row’s blobs are
exhausted.
Auto-drains the previously positioned blob (if not fully read) before
advancing, so the wire stays aligned. After this returns true, read the
blob with read_chunk / copy_blob_to
and inspect it with current_blob_column /
blob_is_null / blob_len.
This is the iteration primitive for
query_stream_rows:
let mut stream = client
.query_stream_rows("SELECT id, doc1, doc2 FROM files", &[])
.await?;
while let Some(row) = stream.next().await? {
let id: i32 = row.get_by_name("id")?;
let _ = id;
while stream.next_blob().await? {
stream.copy_blob_to(&mut sink).await?; // each trailing MAX column
}
}Sourcepub async fn read_chunk(&mut self) -> Result<Option<Bytes>>
pub async fn read_chunk(&mut self) -> Result<Option<Bytes>>
Read the next chunk of the current blob, or None when it is fully
read (or NULL). Reads more packets from the socket as needed.
Chunks are raw bytes, not decoded text. For an NVARCHAR(MAX) /
XML column the bytes are little-endian UCS-2, and a chunk boundary can
fall in the middle of a two-byte code unit (or a surrogate pair) — so do
not decode each chunk to str independently. Concatenate the chunks
first (or stream to a byte sink), then decode the whole value.
Sourcepub async fn copy_blob_to<W>(&mut self, w: &mut W) -> Result<u64>where
W: AsyncWrite + Unpin,
pub async fn copy_blob_to<W>(&mut self, w: &mut W) -> Result<u64>where
W: AsyncWrite + Unpin,
Stream the current row’s blob to an async writer, returning bytes written.
Sourcepub fn blob_len(&self) -> Option<u64>
pub fn blob_len(&self) -> Option<u64>
The current row’s blob length in bytes, once known (after the first
chunk is read). None before that, for a NULL blob, or for an
unknown-length value.
Sourcepub fn blob_is_null(&self) -> bool
pub fn blob_is_null(&self) -> bool
Whether the current row’s blob is NULL.