Skip to main content

nautilus_core/column/
row_access.rs

1//! `RowAccess` trait for abstracting row data access with lifetime support.
2
3use crate::value::Value;
4
5/// Trait for abstracting row data access with lifetime support.
6///
7/// This trait allows both borrowed and owned row implementations,
8/// enabling database-specific optimizations while maintaining a common interface.
9pub trait RowAccess<'row> {
10    /// Get a value by column position (0-indexed).
11    ///
12    /// Returns `None` if the position is out of bounds.
13    fn get_by_pos(&'row self, idx: usize) -> Option<&'row Value>;
14
15    /// Get a value by column name.
16    ///
17    /// Returns `None` if the column doesn't exist.
18    fn get(&'row self, name: &str) -> Option<&'row Value>;
19
20    /// Get the column name at the given position.
21    ///
22    /// Returns `None` if the position is out of bounds.
23    fn column_name(&'row self, idx: usize) -> Option<&'row str>;
24
25    /// Returns the number of columns in the row.
26    fn len(&self) -> usize;
27
28    /// Returns true if the row contains no columns.
29    fn is_empty(&self) -> bool {
30        self.len() == 0
31    }
32}