pub struct RowAccessor<'a> { /* private fields */ }Expand description
A view over a Row that supports name-based access via a
pre-resolved column-name → index lookup table.
RowAccessor is the parameter type of crate::FromRow::from_row; it
borrows the row and a shared lookup map built once per query in
fetch_one_as /
fetch_all_as.
§Example
use hyperdb_api::{FromRow, RowAccessor, Result};
struct User { id: i32, name: String, email: Option<String> }
impl FromRow for User {
fn from_row(row: RowAccessor<'_>) -> Result<Self> {
Ok(User {
id: row.get("id")?,
name: row.get("name")?,
email: row.get_opt("email")?,
})
}
}Implementations§
Source§impl<'a> RowAccessor<'a>
impl<'a> RowAccessor<'a>
Sourcepub fn get<T: RowValue>(&self, name: &str) -> Result<T>
pub fn get<T: RowValue>(&self, name: &str) -> Result<T>
Returns the named column’s value, decoded as T.
§Errors
Error::ColumnwithColumnErrorKind::Missingifnameis not in the result schema.Error::ColumnwithColumnErrorKind::Nullif the cell is SQLNULL.Error::ColumnwithColumnErrorKind::TypeMismatchif the cell value cannot be decoded asT.
Sourcepub fn get_opt<T: RowValue>(&self, name: &str) -> Result<Option<T>>
pub fn get_opt<T: RowValue>(&self, name: &str) -> Result<Option<T>>
Returns the named column’s value as Option<T>. SQL NULL
becomes None; missing columns and type mismatches still error.
§Errors
Error::ColumnwithColumnErrorKind::Missingifnameis not in the result schema.Error::ColumnwithColumnErrorKind::TypeMismatchif the cell is non-NULL but cannot be decoded asT.
Sourcepub fn position<T: RowValue>(&self, idx: usize) -> Result<T>
pub fn position<T: RowValue>(&self, idx: usize) -> Result<T>
Positional escape hatch: returns the value at column idx,
decoded as T.
§Errors
Error::ColumnIndexOutOfBoundsifidxis past the row’s column count.Error::ColumnwithColumnErrorKind::Nullif the cell is SQLNULL. The synthesized name iscol[{idx}].Error::ColumnwithColumnErrorKind::TypeMismatchif the cell value cannot be decoded asT. Same synthesized name.
Sourcepub fn position_opt<T: RowValue>(&self, idx: usize) -> Result<Option<T>>
pub fn position_opt<T: RowValue>(&self, idx: usize) -> Result<Option<T>>
Positional optional access: returns Option<T> for the cell at
idx. SQL NULL becomes None; out-of-bounds and type
mismatches still error. Mirrors get_opt for
positional access.
§Errors
Error::ColumnIndexOutOfBoundsifidxis past the row’s column count.Error::ColumnwithColumnErrorKind::TypeMismatchif the cell is non-NULL but cannot be decoded asT. The synthesized name iscol[{idx}].
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for RowAccessor<'a>
impl<'a> !RefUnwindSafe for RowAccessor<'a>
impl<'a> Send for RowAccessor<'a>
impl<'a> Sync for RowAccessor<'a>
impl<'a> Unpin for RowAccessor<'a>
impl<'a> UnsafeUnpin for RowAccessor<'a>
impl<'a> !UnwindSafe for RowAccessor<'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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request