pub struct Row { /* private fields */ }Expand description
A row from a query result.
Implements the Arc<Bytes> pattern from ADR-004 for reduced memory allocation.
The row holds a shared reference to the raw packet buffer and column slice
information, deferring parsing and allocation until values are accessed.
§Memory Model
Row {
buffer: Arc<Bytes> ──────────► [raw packet data...]
slices: Arc<[ColumnSlice]> ──► [{offset, length, is_null}, ...]
metadata: Arc<ColMetaData> ──► [Column definitions...]
}Multiple Row instances from the same result set share the metadata.
The buffer and slices are unique per row but use Arc for cheap cloning.
§Access Patterns
- Zero-copy:
get_bytes(),get_str()(when UTF-8 valid) - Allocating:
get_string(),get::<String>() - Type-converting:
get::<T>()usesFromSqltrait
Implementations§
Source§impl Row
impl Row
Sourcepub fn new(
buffer: Arc<Bytes>,
slices: Arc<[ColumnSlice]>,
metadata: Arc<ColMetaData>,
) -> Self
pub fn new( buffer: Arc<Bytes>, slices: Arc<[ColumnSlice]>, metadata: Arc<ColMetaData>, ) -> Self
Create a new row with the Arc<Bytes> pattern.
This is the primary constructor for the reduced-copy pattern.
Sourcepub fn get_bytes(&self, index: usize) -> Option<&[u8]>
pub fn get_bytes(&self, index: usize) -> Option<&[u8]>
Returns borrowed slice into buffer (zero additional allocation).
This is the most efficient access method when you need raw bytes.
Sourcepub fn get_str(&self, index: usize) -> Option<Cow<'_, str>>
pub fn get_str(&self, index: usize) -> Option<Cow<'_, str>>
Returns Cow - borrowed if valid UTF-8, owned if conversion needed.
For UTF-8 data, this returns a borrowed reference (zero allocation). For VARCHAR data with collation, uses collation-aware decoding. For UTF-16 data (NVARCHAR), decodes as UTF-16LE.
§Collation-Aware Decoding
When the encoding feature is enabled and the column has collation metadata,
VARCHAR data is decoded using the appropriate character encoding based on the
collation’s LCID. This correctly handles:
- Japanese (Shift_JIS/CP932)
- Simplified Chinese (GB18030/CP936)
- Traditional Chinese (Big5/CP950)
- Korean (EUC-KR/CP949)
- Windows code pages 874, 1250-1258
- SQL Server 2019+ UTF-8 collations
Sourcepub fn get_string(&self, index: usize) -> Option<String>
pub fn get_string(&self, index: usize) -> Option<String>
Allocates new String (explicit allocation).
Use this when you need an owned String.
Sourcepub fn get_stream(&self, index: usize) -> Option<BlobReader>
pub fn get_stream(&self, index: usize) -> Option<BlobReader>
Get a streaming reader for a binary/text column.
Returns a BlobReader that implements tokio::io::AsyncRead for
streaming access to large binary or text columns. This is useful for:
- Streaming large data to files without fully loading into memory
- Processing data in chunks with progress tracking
- Copying data between I/O destinations efficiently
§Supported Column Types
VARBINARY,VARBINARY(MAX)VARCHAR,VARCHAR(MAX)NVARCHAR,NVARCHAR(MAX)TEXT,NTEXT,IMAGE(legacy types)XML
§Example
use tokio::io::AsyncWriteExt;
// Stream a large VARBINARY(MAX) column to a file
let mut reader = row.get_stream(0)?;
let mut file = tokio::fs::File::create("output.bin").await?;
tokio::io::copy(&mut reader, &mut file).await?;§Returns
Some(BlobReader)if the column contains binary/text dataNoneif the column is NULL or the index is out of bounds
Sourcepub fn get_stream_by_name(&self, name: &str) -> Option<BlobReader>
pub fn get_stream_by_name(&self, name: &str) -> Option<BlobReader>
Get a streaming reader for a binary/text column by name.
See get_stream for details.
§Example
let mut reader = row.get_stream_by_name("document_content")?;
// Process the blob stream...Sourcepub fn get<T: FromSql>(&self, index: usize) -> Result<T, TypeError>
pub fn get<T: FromSql>(&self, index: usize) -> Result<T, TypeError>
Get a value by column index with type conversion.
Uses the FromSql trait to convert the raw value to the requested type.
Sourcepub fn get_by_name<T: FromSql>(&self, name: &str) -> Result<T, TypeError>
pub fn get_by_name<T: FromSql>(&self, name: &str) -> Result<T, TypeError>
Get a value by column name with type conversion.
Sourcepub fn try_get<T: FromSql>(&self, index: usize) -> Option<T>
pub fn try_get<T: FromSql>(&self, index: usize) -> Option<T>
Try to get a value by column index, returning None if NULL or not found.
Sourcepub fn try_get_by_name<T: FromSql>(&self, name: &str) -> Option<T>
pub fn try_get_by_name<T: FromSql>(&self, name: &str) -> Option<T>
Try to get a value by column name, returning None if NULL or not found.
Sourcepub fn get_raw(&self, index: usize) -> Option<SqlValue>
pub fn get_raw(&self, index: usize) -> Option<SqlValue>
Get the raw SQL value by index.
Note: This may allocate if values haven’t been cached.
Sourcepub fn get_raw_by_name(&self, name: &str) -> Option<SqlValue>
pub fn get_raw_by_name(&self, name: &str) -> Option<SqlValue>
Get the raw SQL value by column name.
Sourcepub fn metadata(&self) -> &Arc<ColMetaData>
pub fn metadata(&self) -> &Arc<ColMetaData>
Get the shared column metadata.
Sourcepub fn is_null_by_name(&self, name: &str) -> bool
pub fn is_null_by_name(&self, name: &str) -> bool
Check if a column value is NULL by name.