Skip to main content

Row

Struct Row 

Source
pub struct Row { /* private fields */ }
Expand description

A row in a query result.

Implementations§

Source§

impl Row

Source

pub fn raw_values(&self) -> &[Value]

Returns the raw values of the row.

Source

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.
Source

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
Source

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
Source

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.

Source

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 NULL but the target field is not an Option.

Trait Implementations§

Source§

impl Clone for Row

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Row

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromRow for Row

Source§

fn from_row(row: Row) -> Result<Self>

Converts a Spanner Row into the target type. Read more
Source§

impl PartialEq for Row

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Row

Source§

impl TryFrom<Row> for ()

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0> TryFrom<Row> for (T0,)
where T0: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0, T1> TryFrom<Row> for (T0, T1)
where T0: FromValue, T1: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0, T1, T2> TryFrom<Row> for (T0, T1, T2)
where T0: FromValue, T1: FromValue, T2: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0, T1, T2, T3> TryFrom<Row> for (T0, T1, T2, T3)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0, T1, T2, T3, T4> TryFrom<Row> for (T0, T1, T2, T3, T4)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue, T4: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0, T1, T2, T3, T4, T5> TryFrom<Row> for (T0, T1, T2, T3, T4, T5)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue, T4: FromValue, T5: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0, T1, T2, T3, T4, T5, T6> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue, T4: FromValue, T5: FromValue, T6: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue, T4: FromValue, T5: FromValue, T6: FromValue, T7: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
Source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> TryFrom<Row> for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue, T4: FromValue, T5: FromValue, T6: FromValue, T7: FromValue, T8: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
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)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue, T4: FromValue, T5: FromValue, T6: FromValue, T7: FromValue, T8: FromValue, T9: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
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)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue, T4: FromValue, T5: FromValue, T6: FromValue, T7: FromValue, T8: FromValue, T9: FromValue, T10: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.
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)
where T0: FromValue, T1: FromValue, T2: FromValue, T3: FromValue, T4: FromValue, T5: FromValue, T6: FromValue, T7: FromValue, T8: FromValue, T9: FromValue, T10: FromValue, T11: FromValue,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(row: Row) -> Result<Self>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more