Skip to main content

RowResult

Struct RowResult 

Source
pub struct RowResult {
    pub values: Vec<Value>,
}
Available on crate feature sqlite only.
Expand description

A single row from a SQLite query result.

RowResult provides index-based access to column values via RowResult::get().

§Examples

Consume rows from the async streaming API:

use spin_sdk::sqlite::{Connection, Value};

let db = Connection::open_default().await?;
let mut query_result = db.execute(
    "SELECT name, age FROM users WHERE age >= ?",
    [Value::Integer(0)],
).await?;

let name_idx = query_result.columns().iter().position(|c| c == "name").unwrap();

while let Some(row) = query_result.next().await {
    let name: &str = row.get(name_idx).unwrap();
    println!("Found user {name}");
}

query_result.result().await?;

A set of values for each of the columns in a query-result

Fields§

§values: Vec<Value>

Implementations§

Source§

impl RowResult

Source

pub fn get<'a, T: TryFrom<&'a Value>>(&'a self, index: usize) -> Option<T>

Get a value by its column name. The value is converted to the target type.

  • SQLite integers are convertible to Rust integer types (i8, u8, i16, etc. including usize and isize) and bool.
  • SQLite strings are convertible to Rust &str or &u8 (encoded as UTF-8).
  • SQLite reals are convertible to Rust f64.
  • SQLite blobs are convertible to Rust &u8 or &str (interpreted as UTF-8).

To look up by name, you can use QueryResult::rows() or obtain the invoice from QueryResult::columns. If you do not know the type of a value, access the underlying Value enum directly via the RowResult::values field

§Examples
use spin_sdk::sqlite::{Connection, Value};

let db = Connection::open_default().await?;
let mut query_result = db.execute(
    "SELECT name, age FROM users WHERE id = ?",
    [Value::Integer(0)],
).await?;

if let Some(row) = query_result.next().await {
    let name: &str = row.get(0).unwrap();
    let age: u16 = row.get(1).unwrap();
    println!("{name} is {age} years old");
}

query_result.result().await?;

Trait Implementations§

Source§

impl Clone for RowResult

Source§

fn clone(&self) -> RowResult

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RowResult

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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