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
impl RowResult
Sourcepub fn get<'a, T: TryFrom<&'a Value>>(&'a self, index: usize) -> Option<T>
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§
Auto Trait Implementations§
impl Freeze for RowResult
impl RefUnwindSafe for RowResult
impl Send for RowResult
impl Sync for RowResult
impl Unpin for RowResult
impl UnsafeUnpin for RowResult
impl UnwindSafe for RowResult
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
Mutably borrows from an owned value. Read more