Skip to main content
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 calling QueryResult::into_rows_result(). Upon creation, it deserializes result metadata and allocates it. It provides several methods for accessing rows:

Basic Usage

let query_result = session
    .query_unpaged("SELECT a, b FROM ks.tab", &[])
    .await?;

let rows_result = query_result.into_rows_result()?;

let mut rows_iter = rows_result.rows::<(i32, &str)>()?;
while let Some((num, text)) = rows_iter.next().transpose()? {
    println!("{}, {}", num, text);
}

Methods

rows

rows
fn
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 DeserializeRow.Type Parameters:
  • R: DeserializeRow<'frame, 'frame> - Target row type
Returns: Result<TypedRowIterator<'frame, 'frame, R>, RowsError>Example:
let rows_result = session
    .query_unpaged("SELECT a, b FROM ks.tab", &[])
    .await?
    .into_rows_result()?;

// Iterate over rows as tuples
for row in rows_result.rows::<(i32, String)>()? {
    let (a, b) = row?;
    println!("a: {}, b: {}", a, b);
}
With Custom Struct:
use scylla::deserialize::DeserializeRow;

#[derive(DeserializeRow)]
struct User {
    id: i32,
    name: String,
    email: String,
}

let rows_result = session
    .query_unpaged("SELECT id, name, email FROM ks.users", &[])
    .await?
    .into_rows_result()?;

for row in rows_result.rows::<User>()? {
    let user = row?;
    println!("User {}: {}", user.id, user.name);
}

first_row

first_row
fn
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:
  • R: DeserializeRow<'frame, 'frame> - Target row type
Returns: Result<R, FirstRowError>Example:
let rows_result = session
    .query_unpaged("SELECT COUNT(*) FROM ks.tab", &[])
    .await?
    .into_rows_result()?;

let (count,): (i64,) = rows_result.first_row()?;
println!("Total rows: {}", count);
Error Handling:
use scylla::response::query_result::FirstRowError;

match rows_result.first_row::<(i32,)>() {
    Ok((value,)) => println!("First value: {}", value),
    Err(FirstRowError::RowsEmpty) => println!("No rows returned"),
    Err(FirstRowError::TypeCheckFailed(e)) => eprintln!("Type mismatch: {}", e),
    Err(FirstRowError::DeserializationFailed(e)) => eprintln!("Deserialization failed: {}", e),
}

maybe_first_row

maybe_first_row
fn
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
Returns: Result<Option<R>, MaybeFirstRowError>Example:
let rows_result = session
    .query_unpaged("SELECT name FROM ks.users WHERE id = ?", (user_id,))
    .await?
    .into_rows_result()?;

match rows_result.maybe_first_row::<(String,)>()? {
    Some((name,)) => println!("User found: {}", name),
    None => println!("User not found"),
}

single_row

single_row
fn
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.
This method will return an error if there is more than one row in the result. Use it only when you expect exactly one row.
Type Parameters:
  • R: DeserializeRow<'frame, 'frame> - Target row type
Returns: Result<R, SingleRowError>Example:
let rows_result = session
    .query_unpaged("SELECT name FROM ks.users WHERE id = ?", (user_id,))
    .await?
    .into_rows_result()?;

let (name,): (String,) = rows_result.single_row()?;
println!("User name: {}", name);
Error Handling:
use scylla::response::query_result::SingleRowError;

match rows_result.single_row::<(String,)>() {
    Ok((name,)) => println!("Name: {}", name),
    Err(SingleRowError::UnexpectedRowCount(0)) => println!("No rows returned"),
    Err(SingleRowError::UnexpectedRowCount(n)) => println!("Got {} rows, expected 1", n),
    Err(SingleRowError::TypeCheckFailed(e)) => eprintln!("Type mismatch: {}", e),
    Err(SingleRowError::DeserializationFailed(e)) => eprintln!("Deserialization failed: {}", e),
}

rows_num

rows_num
fn
Returns the number of received rows.Returns: usizeExample:
let rows_result = session
    .query_unpaged("SELECT * FROM ks.tab", &[])
    .await?
    .into_rows_result()?;

println!("Received {} rows", rows_result.rows_num());

column_specs

column_specs
fn
Returns column specifications for the result.This provides metadata about the columns returned, including their names and types.Returns: ColumnSpecs<'_, '_>Example:
let rows_result = session
    .query_unpaged("SELECT a, b, c FROM ks.tab", &[])
    .await?
    .into_rows_result()?;

let col_specs = rows_result.column_specs();

println!("Number of columns: {}", col_specs.len());

// Access by index
if let Some(spec) = col_specs.get_by_index(0) {
    println!("First column: {}", spec.name());
}

// Access by name
if let Some((idx, spec)) = col_specs.get_by_name("b") {
    println!("Column 'b' is at index {}", idx);
}

// Iterate over all columns
for spec in col_specs.iter() {
    println!("Column: {} (type: {:?})", spec.name(), spec.typ());
}

warnings

warnings
fn
Returns an iterator over warnings emitted by the database.Returns: impl Iterator<Item = &str>Example:
let rows_result = session
    .query_unpaged("SELECT * FROM ks.tab", &[])
    .await?
    .into_rows_result()?;

for warning in rows_result.warnings() {
    eprintln!("Warning: {}", warning);
}

tracing_id

tracing_id
fn
Returns the tracing ID associated with this CQL request, if tracing was enabled.Returns: Option<Uuid>Example:
if let Some(tracing_id) = rows_result.tracing_id() {
    let tracing_info = session.get_tracing_info(&tracing_id).await?;
    println!("Query duration: {:?}", tracing_info.duration);
}

request_coordinator

request_coordinator
fn
Returns the node and shard that served the request.Returns: &CoordinatorExample:
let coordinator = rows_result.request_coordinator();
println!("Request served by: {:?}", coordinator);

Error Types

RowsError

Returned by rows():
  • TypeCheckFailed(TypeCheckError) - The rows in the response are of incorrect type

FirstRowError

Returned by first_row():
  • RowsEmpty - The request response was of Rows type, but no rows were returned
  • TypeCheckFailed(TypeCheckError) - Type check failed
  • DeserializationFailed(DeserializationError) - Deserialization failed

MaybeFirstRowError

Returned by maybe_first_row():
  • TypeCheckFailed(TypeCheckError) - Type check failed
  • DeserializationFailed(DeserializationError) - Deserialization failed

SingleRowError

Returned by single_row():
  • UnexpectedRowCount(usize) - Expected exactly one row, but got a different count
  • TypeCheckFailed(TypeCheckError) - Type check failed
  • DeserializationFailed(DeserializationError) - Deserialization failed

ColumnSpecs

The ColumnSpecs type provides access to column metadata:
  • len() - Number of columns
  • get_by_index(k: usize) - Get column specification by index
  • get_by_name(name: &str) - Get column specification and index by name
  • iter() - Iterator over column specifications
  • QueryResult - Transform this into QueryRowsResult using into_rows_result()
  • DeserializeRow - Trait for types that can be deserialized from a row
  • Session - Main API for executing queries

Build docs developers (and LLMs) love