QueryRowsResult enables deserialization of rows received from the database in a QueryResult. It provides generic methods for typed access to the data by deserializing rows on the fly.
Overview
This struct is created by callingQueryResult::into_rows_result(). Upon creation, it deserializes result metadata and allocates it.
It provides several methods for accessing rows:
rows()- Iterator over all rowsfirst_row()andmaybe_first_row()- Access the first rowsingle_row()- Access the first row, asserting it’s the only one
Basic Usage
Methods
rows
Returns an iterator over the received rows.The iterator deserializes rows on the fly to the type provided as a type parameter. The type must implement With Custom Struct:
DeserializeRow.Type Parameters:R: DeserializeRow<'frame, 'frame>- Target row type
Result<TypedRowIterator<'frame, 'frame, R>, RowsError>Example:first_row
Returns the first row of the received result.Fails if no rows were returned, if the rows are of incorrect type, or if deserialization fails.Type Parameters:Error Handling:
R: DeserializeRow<'frame, 'frame>- Target row type
Result<R, FirstRowError>Example:maybe_first_row
Returns
Option<R> containing the first row of the result, or None if no rows were returned.Fails if the rows are of incorrect type or if deserialization fails.Type Parameters:R: DeserializeRow<'frame, 'frame>- Target row type
Result<Option<R>, MaybeFirstRowError>Example:single_row
Returns the only received row.Fails if the result contains zero rows or more than one row. Also fails if the rows are of incorrect type or if deserialization fails.Type Parameters:Error Handling:
R: DeserializeRow<'frame, 'frame>- Target row type
Result<R, SingleRowError>Example:rows_num
Returns the number of received rows.Returns:
usizeExample:column_specs
Returns column specifications for the result.This provides metadata about the columns returned, including their names and types.Returns:
ColumnSpecs<'_, '_>Example:warnings
Returns an iterator over warnings emitted by the database.Returns:
impl Iterator<Item = &str>Example:tracing_id
Returns the tracing ID associated with this CQL request, if tracing was enabled.Returns:
Option<Uuid>Example:request_coordinator
Returns the node and shard that served the request.Returns:
&CoordinatorExample:Error Types
RowsError
Returned byrows():
TypeCheckFailed(TypeCheckError)- The rows in the response are of incorrect type
FirstRowError
Returned byfirst_row():
RowsEmpty- The request response was of Rows type, but no rows were returnedTypeCheckFailed(TypeCheckError)- Type check failedDeserializationFailed(DeserializationError)- Deserialization failed
MaybeFirstRowError
Returned bymaybe_first_row():
TypeCheckFailed(TypeCheckError)- Type check failedDeserializationFailed(DeserializationError)- Deserialization failed
SingleRowError
Returned bysingle_row():
UnexpectedRowCount(usize)- Expected exactly one row, but got a different countTypeCheckFailed(TypeCheckError)- Type check failedDeserializationFailed(DeserializationError)- Deserialization failed
ColumnSpecs
TheColumnSpecs type provides access to column metadata:
len()- Number of columnsget_by_index(k: usize)- Get column specification by indexget_by_name(name: &str)- Get column specification and index by nameiter()- Iterator over column specifications
Related Types
QueryResult- Transform this intoQueryRowsResultusinginto_rows_result()DeserializeRow- Trait for types that can be deserialized from a rowSession- Main API for executing queries
