QueryResult represents the result of any kind of CQL request to the database. It holds response data in a raw binary form, which can be transformed into a typed result for row access.
Overview
QueryResult is returned from query execution methods like query_unpaged() and execute_unpaged(). It represents a single page of results if paging is used.
The received rows and metadata are kept in raw binary form. To deserialize and access them, transform QueryResult to QueryRowsResult by calling into_rows_result().
This is the result of a single CQL request. If you use paging, this will contain exactly one page.
Methods
request_coordinator
Returns the node and shard that served the request.Returns:
&CoordinatorExample:warnings
Returns an iterator over warnings emitted by the database during query execution.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:is_rows
Returns
true if the response is of Rows type (e.g., from a SELECT query).Returns: boolExample:result_not_rows
Returns
Ok for requests that shouldn’t contain any rows (e.g., INSERT, UPDATE, DELETE).Will return Ok for an INSERT result, but a SELECT result (even an empty one) will cause an error. This is the opposite of into_rows_result().Returns: Result<(), ResultNotRowsError>Example:into_rows_result
Transforms the result into Returns: Error Handling:
QueryRowsResult to enable deserializing rows.Deserializes result metadata and allocates it. Returns an error if the response is not of Rows kind or if metadata deserialization failed.If the response is not of Rows kind, the original
QueryResult is returned in the error variant IntoRowsResultError::ResultNotRows, allowing you to recover it.Result<QueryRowsResult, IntoRowsResultError>Example:Error Types
IntoRowsResultError
Returned byinto_rows_result():
ResultNotRows(QueryResult)- Result is not of Rows kind. Contains the originalQueryResultso it’s not lost.ResultMetadataLazyDeserializationError- Failed to deserialize result metadata.
ResultNotRowsError
Returned byresult_not_rows() when the response was unexpectedly of Rows kind.
Related Types
QueryRowsResult- Enables typed access to rows returned from the databaseSession- Main API for executing queries that returnQueryResultCoordinator- Information about the node that coordinated the request
