mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-30 05:11:13 +00:00
feat(core): add Row::get, Row::get_raw
This commit is contained in:
parent
21f3a83c5f
commit
eddd873f4d
@ -40,12 +40,25 @@ pub trait Row: 'static + Send + Sync {
|
||||
/// Returns the column index, given the name of the column.
|
||||
fn try_index_of(&self, name: &str) -> crate::Result<usize>;
|
||||
|
||||
/// Returns the decoded value at the index.
|
||||
fn get<'r, T, I>(&'r self, index: I) -> T
|
||||
where
|
||||
I: ColumnIndex<Self>,
|
||||
T: Decode<'r, Self::Database>;
|
||||
|
||||
/// Returns the decoded value at the index.
|
||||
fn try_get<'r, T, I>(&'r self, index: I) -> crate::Result<T>
|
||||
where
|
||||
I: ColumnIndex<Self>,
|
||||
T: Decode<'r, Self::Database>;
|
||||
|
||||
/// Returns the raw representation of the value at the index.
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
fn get_raw<'r, I: ColumnIndex<Self>>(
|
||||
&'r self,
|
||||
index: I,
|
||||
) -> <Self::Database as HasRawValue<'r>>::RawValue;
|
||||
|
||||
/// Returns the raw representation of the value at the index.
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
fn try_get_raw<'r, I: ColumnIndex<Self>>(
|
||||
|
||||
@ -79,6 +79,15 @@ impl MySqlRow {
|
||||
.ok_or_else(|| Error::ColumnNotFound { name: name.to_owned().into_boxed_str() })
|
||||
}
|
||||
|
||||
/// Returns the decoded value at the index.
|
||||
pub fn get<'r, T, I>(&'r self, index: I) -> T
|
||||
where
|
||||
I: ColumnIndex<Self>,
|
||||
T: Decode<'r, MySql>,
|
||||
{
|
||||
self.try_get(index).unwrap()
|
||||
}
|
||||
|
||||
/// Returns the decoded value at the index.
|
||||
pub fn try_get<'r, T, I>(&'r self, index: I) -> Result<T>
|
||||
where
|
||||
@ -88,6 +97,15 @@ impl MySqlRow {
|
||||
Ok(self.try_get_raw(index)?.decode()?)
|
||||
}
|
||||
|
||||
/// Returns the raw representation of the value at the index.
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
pub fn get_raw<'r, I>(&'r self, index: I) -> MySqlRawValue<'r>
|
||||
where
|
||||
I: ColumnIndex<Self>,
|
||||
{
|
||||
self.try_get_raw(index).unwrap()
|
||||
}
|
||||
|
||||
/// Returns the raw representation of the value at the index.
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
pub fn try_get_raw<'r, I>(&'r self, index: I) -> Result<MySqlRawValue<'r>>
|
||||
@ -146,6 +164,14 @@ impl Row for MySqlRow {
|
||||
self.try_index_of(name)
|
||||
}
|
||||
|
||||
fn get<'r, T, I>(&'r self, index: I) -> T
|
||||
where
|
||||
I: ColumnIndex<Self>,
|
||||
T: Decode<'r, MySql>,
|
||||
{
|
||||
self.get(index)
|
||||
}
|
||||
|
||||
fn try_get<'r, T, I>(&'r self, index: I) -> Result<T>
|
||||
where
|
||||
I: ColumnIndex<Self>,
|
||||
@ -154,6 +180,11 @@ impl Row for MySqlRow {
|
||||
self.try_get(index)
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
fn get_raw<'r, I: ColumnIndex<Self>>(&'r self, index: I) -> MySqlRawValue<'r> {
|
||||
self.get_raw(index)
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
fn try_get_raw<'r, I: ColumnIndex<Self>>(&'r self, index: I) -> Result<MySqlRawValue<'r>> {
|
||||
self.try_get_raw(index)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user