pub struct Row<'a> { /* private fields */ }
Expand description
A database row result.
There are two representations of a SQLite row in the SDK. This type is useful for addressing elements by column name, and is obtained from the QueryResult::rows() function. The RowResult type is obtained from the QueryResult::rows field, and provides index-based lookup or low-level access to row values via a vector.
Implementations§
Source§impl<'a> Row<'a>
impl<'a> Row<'a>
Sourcepub fn get<T: TryFrom<&'a Value>>(&self, column: &str) -> Option<T>
pub fn get<T: TryFrom<&'a Value>>(&self, column: &str) -> 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).
If your code does not know the type in advance, use RowResult instead of Row
to
access the underlying Value enum.
§Examples
use spin_sdk::sqlite::{Connection, Value};
let db = Connection::open_default()?;
let query_result = db.execute(
"SELECT * FROM users WHERE id = ?",
&[Value::Integer(user_id)]
)?;
let user_row = query_result.rows().next().unwrap();
let name = user_row.get::<&str>("name").unwrap();
let age = user_row.get::<u16>("age").unwrap();
Auto Trait Implementations§
impl<'a> Freeze for Row<'a>
impl<'a> RefUnwindSafe for Row<'a>
impl<'a> Send for Row<'a>
impl<'a> Sync for Row<'a>
impl<'a> Unpin for Row<'a>
impl<'a> UnwindSafe for Row<'a>
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