#[non_exhaustive]pub struct Row { /* private fields */ }Expand description
A single row from a query result.
Implementations§
Source§impl Row
impl Row
Sourcepub fn columns(&self) -> &[FieldDescription]
pub fn columns(&self) -> &[FieldDescription]
Returns the column descriptions.
Sourcepub fn get_raw(&self, index: usize) -> Option<&[u8]>
pub fn get_raw(&self, index: usize) -> Option<&[u8]>
Returns the raw bytes for the column at index, or None if NULL.
Sourcepub fn get<T: FromSql>(&self, index: usize) -> Result<T>
pub fn get<T: FromSql>(&self, index: usize) -> Result<T>
Decode the column at index as type T.
§Type inference
The type T must implement FromSql for the column’s PostgreSQL
type OID. If the types don’t match, a TypeConversion error is
returned.
§NULL handling
If the column value is SQL NULL, this method returns
Err(PgError::UnexpectedNull). To handle NULL values, use
Option<T> as the type parameter:
let val: Option<i32> = row.get(0)?; // NULL → None§Errors
PgError::ColumnIndexOutOfBounds— index exceeds column countPgError::UnexpectedNull— column is NULL andTis notOptionPgError::TypeConversion— type mismatch between PG type andT
Sourcepub fn get_by_name<T: FromSql>(&self, name: &str) -> Result<T>
pub fn get_by_name<T: FromSql>(&self, name: &str) -> Result<T>
Decode a column by name as type T.
Column name lookup is O(n) where n is the number of columns. For performance-critical code, prefer index-based access.
§Errors
PgError::ColumnNotFound— no column with the given namePgError::UnexpectedNull— column is NULL andTis notOptionPgError::TypeConversion— type mismatch between PG type andT
Sourcepub fn column_name(&self, index: usize) -> Option<&str>
pub fn column_name(&self, index: usize) -> Option<&str>
Get the name of a column by index.
Returns None if the index is out of bounds.
Sourcepub fn column_index(&self, name: &str) -> Option<usize>
pub fn column_index(&self, name: &str) -> Option<usize>
Get the index of a column by name.
Column name lookup is O(n) where n is the number of columns. For performance-critical code, prefer index-based access.