mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-03 04:09:50 +00:00
simplify lifetimes on Row
This commit is contained in:
parent
fc6e6a65f7
commit
cb2e3220e0
@ -37,9 +37,8 @@ impl<'c> Row<'c> for MySqlRow<'c> {
|
||||
self.row.len()
|
||||
}
|
||||
|
||||
fn try_get_raw<'r, I>(&'r self, index: I) -> crate::Result<MySql, Option<MySqlValue<'r>>>
|
||||
fn try_get_raw<I>(&self, index: I) -> crate::Result<MySql, Option<MySqlValue<'c>>>
|
||||
where
|
||||
'c: 'r,
|
||||
I: ColumnIndex<Self::Database>,
|
||||
{
|
||||
let index = index.resolve(self)?;
|
||||
|
||||
@ -42,9 +42,8 @@ impl<'c> Row<'c> for PgRow<'c> {
|
||||
self.data.len()
|
||||
}
|
||||
|
||||
fn try_get_raw<'r, I>(&'r self, index: I) -> crate::Result<Postgres, Option<PgValue<'r>>>
|
||||
fn try_get_raw<I>(&self, index: I) -> crate::Result<Postgres, Option<PgValue<'c>>>
|
||||
where
|
||||
'c: 'r,
|
||||
I: ColumnIndex<Self::Database>,
|
||||
{
|
||||
let index = index.resolve(self)?;
|
||||
|
||||
@ -24,32 +24,29 @@ pub trait Row<'c>: Unpin + Send {
|
||||
/// Returns the number of values in the row.
|
||||
fn len(&self) -> usize;
|
||||
|
||||
fn get<'r, T, I>(&'r self, index: I) -> T
|
||||
fn get<T, I>(&self, index: I) -> T
|
||||
where
|
||||
'c: 'r,
|
||||
T: Type<Self::Database>,
|
||||
I: ColumnIndex<Self::Database>,
|
||||
T: Decode<'r, Self::Database>,
|
||||
T: Decode<'c, Self::Database>,
|
||||
{
|
||||
self.try_get::<T, I>(index).unwrap()
|
||||
}
|
||||
|
||||
fn try_get<'r, T, I>(&'r self, index: I) -> crate::Result<Self::Database, T>
|
||||
fn try_get<T, I>(&self, index: I) -> crate::Result<Self::Database, T>
|
||||
where
|
||||
'c: 'r,
|
||||
T: Type<Self::Database>,
|
||||
I: ColumnIndex<Self::Database>,
|
||||
T: Decode<'r, Self::Database>,
|
||||
T: Decode<'c, Self::Database>,
|
||||
{
|
||||
Ok(Decode::decode(self.try_get_raw(index)?)?)
|
||||
}
|
||||
|
||||
fn try_get_raw<'r, I>(
|
||||
&'r self,
|
||||
fn try_get_raw<I>(
|
||||
&self,
|
||||
index: I,
|
||||
) -> crate::Result<Self::Database, <Self::Database as HasRawValue<'r>>::RawValue>
|
||||
) -> crate::Result<Self::Database, <Self::Database as HasRawValue<'c>>::RawValue>
|
||||
where
|
||||
'c: 'r,
|
||||
I: ColumnIndex<Self::Database>;
|
||||
}
|
||||
|
||||
@ -72,7 +69,7 @@ macro_rules! impl_from_row_for_tuple {
|
||||
where
|
||||
$($T: 'c,)+
|
||||
$($T: crate::types::Type<$db>,)+
|
||||
$($T: for<'r> crate::decode::Decode<'r, $db>,)+
|
||||
$($T: crate::decode::Decode<'c, $db>,)+
|
||||
{
|
||||
#[inline]
|
||||
fn from_row(row: $r<'c>) -> crate::Result<$db, Self> {
|
||||
|
||||
@ -7,11 +7,19 @@ use crate::sqlite::{Sqlite, SqliteConnection};
|
||||
pub struct SqliteRow<'c> {
|
||||
pub(super) values: usize,
|
||||
pub(super) statement: Option<usize>,
|
||||
pub(super) connection: &'c mut SqliteConnection,
|
||||
pub(super) connection: &'c SqliteConnection,
|
||||
}
|
||||
|
||||
// Accessing values from the statement object is
|
||||
// safe across threads as long as we don't call [sqlite3_step]
|
||||
// That should not be possible as long as an immutable borrow is held on the connection
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe impl Send for SqliteRow<'_> {}
|
||||
|
||||
impl<'c> SqliteRow<'c> {
|
||||
fn statement(&'c self) -> &'c Statement {
|
||||
#[inline]
|
||||
fn statement(&self) -> &'c Statement {
|
||||
self.connection.statement(self.statement)
|
||||
}
|
||||
}
|
||||
@ -24,15 +32,14 @@ impl<'c> Row<'c> for SqliteRow<'c> {
|
||||
self.values
|
||||
}
|
||||
|
||||
fn try_get_raw<'r, I>(&'r self, index: I) -> crate::Result<Sqlite, SqliteValue<'r>>
|
||||
fn try_get_raw<I>(&self, index: I) -> crate::Result<Sqlite, SqliteValue<'c>>
|
||||
where
|
||||
'c: 'r,
|
||||
I: ColumnIndex<Self::Database>,
|
||||
{
|
||||
let index = index.resolve(self)?;
|
||||
let value = SqliteValue::new(self.statement(), index);
|
||||
|
||||
Ok(value)
|
||||
Ok(SqliteValue {
|
||||
statement: self.statement(),
|
||||
index: index.resolve(self)? as i32,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,18 +11,8 @@ use libsqlite3_sys::{
|
||||
use crate::sqlite::statement::Statement;
|
||||
|
||||
pub struct SqliteValue<'c> {
|
||||
index: i32,
|
||||
statement: &'c Statement,
|
||||
}
|
||||
|
||||
impl<'c> SqliteValue<'c> {
|
||||
#[inline]
|
||||
pub(super) fn new(statement: &'c Statement, index: usize) -> Self {
|
||||
Self {
|
||||
statement,
|
||||
index: index as i32,
|
||||
}
|
||||
}
|
||||
pub(super) index: i32,
|
||||
pub(super) statement: &'c Statement,
|
||||
}
|
||||
|
||||
// https://www.sqlite.org/c3ref/column_blob.html
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user