Row

Struct Row 

Source
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 RowSet::rows() function. The DbValue vector representation is obtained from the RowSet::rows field, and provides index-based lookup or low-level access to row values via a vector.

Implementations§

Source§

impl Row<'_>

Source

pub fn get<T: Decode>(&self, column: &str) -> Option<T>

Get a value by its column name. The value is converted to the target type as per the conversion table shown in the module documentation.

This function returns None for both no such column and failed conversion. You should use it only if you do not need to address errors (that is, if you know that conversion should never fail). If your code does not know the type in advance, use the raw RowSet::rows vector instead of the Row wrapper to access the underlying DbValue enum: this will allow you to determine the type and process it accordingly.

Additionally, this function performs a name lookup each time it is called. If you are iterating over a large number of rows, it’s more efficient to use column indexes, either calculated or statically known from the column order in the SQL.

§Examples
use spin_sdk::pg4::{Connection, DbValue};

let db = Connection::open("host=localhost user=postgres password=my_password dbname=mydb")?;
let query_result = db.query(
    "SELECT * FROM users WHERE id = $1",
    &[user_id.into()]
)?;
let user_row = query_result.rows().next().unwrap();

let name = user_row.get::<String>("name").unwrap();
let age = user_row.get::<i16>("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> 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> 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, 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