pub struct Row { /* private fields */ }Expand description
A single row returned from a database query.
Rows provide both index-based and name-based access to column values.
Column metadata is shared via Arc for memory efficiency.
Implementations§
Source§impl Row
impl Row
Sourcepub fn new(column_names: Vec<String>, values: Vec<Value>) -> Self
pub fn new(column_names: Vec<String>, values: Vec<Value>) -> Self
Create a new row with the given columns and values.
For multiple rows from the same result set, prefer with_columns
to share the column metadata.
Sourcepub fn subset_by_prefix(&self, prefix: &str) -> Self
pub fn subset_by_prefix(&self, prefix: &str) -> Self
Extract a subset of columns with a given prefix.
This is useful for eager loading where columns are aliased like
table__column. This method extracts columns matching prefix__*
and returns a new Row with the prefix stripped.
§Example
let row = Row::new(
vec!["heroes__id", "heroes__name", "teams__id", "teams__name"],
vec![Value::Int(1), Value::Text("Hero".into()), Value::Int(10), Value::Text("Team".into())],
);
let hero_row = row.subset_by_prefix("heroes");
// hero_row has columns: ["id", "name"] with values [1, "Hero"]Sourcepub fn has_prefix(&self, prefix: &str) -> bool
pub fn has_prefix(&self, prefix: &str) -> bool
Check if this row has any columns with the given prefix.
Useful for checking if a LEFT JOIN returned NULL (no matching rows).
Sourcepub fn prefix_is_all_null(&self, prefix: &str) -> bool
pub fn prefix_is_all_null(&self, prefix: &str) -> bool
Check if all values with a given prefix are NULL.
Used to detect LEFT JOIN rows where no related record exists.
Sourcepub fn with_columns(columns: Arc<ColumnInfo>, values: Vec<Value>) -> Self
pub fn with_columns(columns: Arc<ColumnInfo>, values: Vec<Value>) -> Self
Create a new row with shared column metadata.
This is more efficient for creating multiple rows from the same query.
Sourcepub fn column_info(&self) -> Arc<ColumnInfo>
pub fn column_info(&self) -> Arc<ColumnInfo>
Get the shared column metadata.
Use this to create additional rows that share the same column info.
Sourcepub fn get_by_name(&self, name: &str) -> Option<&Value>
pub fn get_by_name(&self, name: &str) -> Option<&Value>
Get a value by column name. O(1) operation via HashMap lookup.
Sourcepub fn contains_column(&self, name: &str) -> bool
pub fn contains_column(&self, name: &str) -> bool
Check if a column exists by name.
Sourcepub fn get_as<T: FromValue>(&self, index: usize) -> Result<T>
pub fn get_as<T: FromValue>(&self, index: usize) -> Result<T>
Get a typed value by column index.
Sourcepub fn get_named<T: FromValue>(&self, name: &str) -> Result<T>
pub fn get_named<T: FromValue>(&self, name: &str) -> Result<T>
Get a typed value by column name.
Sourcepub fn column_names(&self) -> impl Iterator<Item = &str>
pub fn column_names(&self) -> impl Iterator<Item = &str>
Get all column names.