pub struct Row { /* private fields */ }Expand description
A row in a query result.
Implementations§
Source§impl Row
impl Row
Sourcepub fn raw_values(&self) -> &[Value]
pub fn raw_values(&self) -> &[Value]
Returns the raw values of the row.
Sourcepub fn is_null(&self, index: impl ColumnIndex) -> Result<bool>
pub fn is_null(&self, index: impl ColumnIndex) -> Result<bool>
Returns true if the value at the specified column name or index is null.
§Example
let client = Spanner::builder().build().await?;
let db_client = client.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = db_client.single_use().build();
let mut result_set = transaction.execute_query(Statement::builder("SELECT NULL AS Age").build()).await?;
if let Some(row) = result_set.next().await {
let is_null = row?.is_null("Age")?;
println!("Is null: {}", is_null);
}§Arguments
index- The column name (string) or index (zero-based integer).
§Returns
Ok(bool)if the value is null or not.Err(Error)if the column name or index is invalid.
Sourcepub fn get<T: FromValue>(&self, index: impl ColumnIndex) -> Result<T>
pub fn get<T: FromValue>(&self, index: impl ColumnIndex) -> Result<T>
Retrieves a value from the row by column name or zero-based index.
§Example
let client = Spanner::builder().build().await?;
let db_client = client.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = db_client.single_use().build();
let mut result_set = transaction.execute_query(Statement::builder("SELECT 42 AS Age").build()).await?;
if let Some(row) = result_set.next().await {
let age: i64 = row?.get("Age")?;
println!("Age: {}", age);
}§Arguments
index- The column name (string) or index (zero-based integer).
§Returns
Ok(T)if the value was successfully retrieved and converted to typeT.Err(Error)if:- The column name or index is invalid. The underlying
RowErrorcan be extracted usingRowError::extract. - The column value is incompatible with type
Tor conversion fails. The underlyingRowError::TypeConversioncan be extracted usingRowError::extract, and the innerConvertErrorcan also be extracted usingConvertError::extract.
- The column name or index is invalid. The underlying
Sourcepub fn take<T: FromValue>(&mut self, index: impl ColumnIndex) -> Result<T>
pub fn take<T: FromValue>(&mut self, index: impl ColumnIndex) -> Result<T>
Takes ownership of a value from the row by column name or zero-based index, replacing the column in the row with a null value.
§Example
let database_client = client.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = database_client.single_use().build();
let mut result_set = transaction
.execute_query(Statement::builder("SELECT 'hello' AS greeting").build())
.await?;
if let Some(row) = result_set.next().await {
let mut row = row?;
let greeting: String = row.take("greeting")?;
assert_eq!(greeting, "hello");
// Subsequent reads treat the column as null:
assert!(row.is_null("greeting")?);
}This method avoids cloning heap-allocated types such as String, Vec<T>,
serde_json::Value, and Value.
§Note
If the SQL query contains duplicate column names, indexing by column name resolves to the first matching column. Once taken, that column becomes null, and subsequent calls with the same column name will still resolve to that first (now null) column. To take subsequent duplicate columns, index by column position.
If type conversion fails, the column value in the row has already been
replaced with NULL and cannot be recovered.
§Arguments
index- The column name (string) or index (zero-based integer).
§Returns
Ok(T)if the value was successfully taken and converted to typeT.Err(Error)if:- The column name or index is invalid. The underlying
RowErrorcan be extracted usingRowError::extract. - The column value is incompatible with type
Tor conversion fails. The underlyingRowError::TypeConversioncan be extracted usingRowError::extract, and the innerConvertErrorcan also be extracted usingConvertError::extract.
- The column name or index is invalid. The underlying
Sourcepub fn into_values(self) -> Vec<Value>
pub fn into_values(self) -> Vec<Value>
Consumes the row and returns its raw values.
§Example
let database_client = client.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = database_client.single_use().build();
let mut result_set = transaction
.execute_query(Statement::builder("SELECT 1 AS a, 'b' AS b").build())
.await?;
if let Some(row) = result_set.next().await {
let values = row?.into_values();
assert_eq!(values.len(), 2);
}§Returns
Returns a Vec<Value> containing the row’s values in ordinal column order.
Sourcepub fn into_record<T: FromRow>(self) -> Result<T>
pub fn into_record<T: FromRow>(self) -> Result<T>
Converts this row into a typed record implementing FromRow.
§Example
let database_client = client.database_client("projects/p/instances/i/databases/d").build().await?;
let transaction = database_client.single_use().build();
let mut result_set = transaction
.execute_query(Statement::builder("SELECT 'user-1', 42").build())
.await?;
if let Some(row) = result_set.next().await {
let (id, age): (String, i64) = row?.into_record()?;
println!("User: {id}, age: {age}");
}This is equivalent to calling T::from_row(self).
§Errors
Returns an Error if:
- A required column name or positional index is missing from the row.
- A column value cannot be converted into the target field type.
- A column is
NULLbut the target field is not anOption.
Trait Implementations§
impl StructuralPartialEq for Row
Source§impl<T0, T1, T2> TryFrom<Row> for (T0, T1, T2)
impl<T0, T1, T2> TryFrom<Row> for (T0, T1, T2)
Source§impl<T0, T1, T2, T3> TryFrom<Row> for (T0, T1, T2, T3)
impl<T0, T1, T2, T3> TryFrom<Row> for (T0, T1, T2, T3)
Source§impl<T0, T1, T2, T3, T4> TryFrom<Row> for (T0, T1, T2, T3, T4)
impl<T0, T1, T2, T3, T4> TryFrom<Row> for (T0, T1, T2, T3, T4)
Source§impl<T0, T1, T2, T3, T4, T5> TryFrom<Row> for (T0, T1, T2, T3, T4, T5)
impl<T0, T1, T2, T3, T4, T5> TryFrom<Row> for (T0, T1, T2, T3, T4, T5)
Source§impl<T0, T1, T2, T3, T4, T5, T6> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6)
impl<T0, T1, T2, T3, T4, T5, T6> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6)
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7)
impl<T0, T1, T2, T3, T4, T5, T6, T7> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7)
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
Auto Trait Implementations§
impl Forget for Row
impl Freeze for Row
impl Move for Row
impl RefUnwindSafe for Row
impl Send for Row
impl Sync for Row
impl Unpin for Row
impl UnsafeUnpin for Row
impl UnwindSafe for Row
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request