diff --git a/sqlx-core/src/row.rs b/sqlx-core/src/row.rs index b4cc992c..19edd974 100644 --- a/sqlx-core/src/row.rs +++ b/sqlx-core/src/row.rs @@ -19,6 +19,15 @@ pub trait Row: 'static + Send + Sync { /// Returns a reference to the columns in the row. fn columns(&self) -> &[::Column]; + /// Returns the column at the index, if available. + fn column>(&self, index: I) -> &::Column; + + /// Returns the column at the index, if available. + fn try_column>( + &self, + index: I, + ) -> crate::Result<&::Column>; + /// Returns the column name, given the index of the column. fn column_name_of(&self, index: usize) -> &str; diff --git a/sqlx-mysql/src/row.rs b/sqlx-mysql/src/row.rs index 5ce3410e..5be80825 100644 --- a/sqlx-mysql/src/row.rs +++ b/sqlx-mysql/src/row.rs @@ -41,6 +41,16 @@ impl MySqlRow { &self.columns } + /// Returns the column at the index, if available. + fn column>(&self, index: I) -> &MySqlColumn { + self.try_column(index).unwrap() + } + + /// Returns the column at the index, if available. + fn try_column>(&self, index: I) -> Result<&MySqlColumn> { + Ok(&self.columns[index.get(self)?]) + } + /// Returns the column name, given the index of the column. #[must_use] pub fn column_name_of(&self, index: usize) -> &str { @@ -112,6 +122,14 @@ impl Row for MySqlRow { self.columns() } + fn column>(&self, index: I) -> &MySqlColumn { + self.column(index) + } + + fn try_column>(&self, index: I) -> Result<&MySqlColumn> { + self.try_column(index) + } + fn column_name_of(&self, index: usize) -> &str { self.column_name_of(index) }