mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
feat(core): add Row::column, Row::try_column (from 0.5)
This commit is contained in:
parent
d8e4030cb8
commit
21f3a83c5f
@ -19,6 +19,15 @@ pub trait Row: 'static + Send + Sync {
|
||||
/// Returns a reference to the columns in the row.
|
||||
fn columns(&self) -> &[<Self::Database as Database>::Column];
|
||||
|
||||
/// Returns the column at the index, if available.
|
||||
fn column<I: ColumnIndex<Self>>(&self, index: I) -> &<Self::Database as Database>::Column;
|
||||
|
||||
/// Returns the column at the index, if available.
|
||||
fn try_column<I: ColumnIndex<Self>>(
|
||||
&self,
|
||||
index: I,
|
||||
) -> crate::Result<&<Self::Database as Database>::Column>;
|
||||
|
||||
/// Returns the column name, given the index of the column.
|
||||
fn column_name_of(&self, index: usize) -> &str;
|
||||
|
||||
|
||||
@ -41,6 +41,16 @@ impl MySqlRow {
|
||||
&self.columns
|
||||
}
|
||||
|
||||
/// Returns the column at the index, if available.
|
||||
fn column<I: ColumnIndex<Self>>(&self, index: I) -> &MySqlColumn {
|
||||
self.try_column(index).unwrap()
|
||||
}
|
||||
|
||||
/// Returns the column at the index, if available.
|
||||
fn try_column<I: ColumnIndex<Self>>(&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<I: ColumnIndex<Self>>(&self, index: I) -> &MySqlColumn {
|
||||
self.column(index)
|
||||
}
|
||||
|
||||
fn try_column<I: ColumnIndex<Self>>(&self, index: I) -> Result<&MySqlColumn> {
|
||||
self.try_column(index)
|
||||
}
|
||||
|
||||
fn column_name_of(&self, index: usize) -> &str {
|
||||
self.column_name_of(index)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user