diff --git a/src/database/connection.rs b/src/database/connection.rs index b6a3c1652..6effc7c77 100644 --- a/src/database/connection.rs +++ b/src/database/connection.rs @@ -34,17 +34,15 @@ pub trait ConnectionTrait: Sync { } /// Stream query results -pub trait StreamTrait: Send + Sync { +pub trait StreamTrait<'a>: Send + Sync { /// Create a stream for the [QueryResult] - type Stream<'a>: Stream> + Send - where - Self: 'a; + type Stream: Stream> + Send; /// Execute a [Statement] and return a stream of results - fn stream<'a>( + fn stream( &'a self, stmt: Statement, - ) -> Pin, DbErr>> + 'a + Send>>; + ) -> Pin> + 'a + Send>>; } #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/src/database/db_connection.rs b/src/database/db_connection.rs index 9e40fb88e..66c1ae6e8 100644 --- a/src/database/db_connection.rs +++ b/src/database/db_connection.rs @@ -165,15 +165,15 @@ impl ConnectionTrait for DatabaseConnection { } #[async_trait::async_trait] -impl StreamTrait for DatabaseConnection { - type Stream<'a> = crate::QueryStream; +impl<'a> StreamTrait<'a> for DatabaseConnection { + type Stream = crate::QueryStream; #[instrument(level = "trace")] #[allow(unused_variables, unreachable_code)] - fn stream<'a>( + fn stream( &'a self, stmt: Statement, - ) -> Pin, DbErr>> + 'a + Send>> { + ) -> Pin> + 'a + Send>> { Box::pin(async move { Ok(match self { #[cfg(feature = "sqlx-mysql")] diff --git a/src/database/transaction.rs b/src/database/transaction.rs index 224f6f924..e1395d357 100644 --- a/src/database/transaction.rs +++ b/src/database/transaction.rs @@ -417,14 +417,16 @@ impl ConnectionTrait for DatabaseTransaction { } } -impl StreamTrait for DatabaseTransaction { - type Stream<'a> = TransactionStream<'a>; +#[async_trait::async_trait] +#[allow(unused_variables)] +impl<'a> StreamTrait<'a> for DatabaseTransaction { + type Stream = TransactionStream<'a>; #[instrument(level = "trace")] - fn stream<'a>( + fn stream( &'a self, stmt: Statement, - ) -> Pin, DbErr>> + 'a + Send>> { + ) -> Pin> + 'a + Send>> { Box::pin(async move { let conn = self.conn.lock().await; Ok(crate::TransactionStream::build( diff --git a/src/executor/select.rs b/src/executor/select.rs index a31b2a831..ed798d940 100644 --- a/src/executor/select.rs +++ b/src/executor/select.rs @@ -275,7 +275,7 @@ where db: &'a C, ) -> Result> + 'b + Send, DbErr> where - C: ConnectionTrait + StreamTrait + Send, + C: ConnectionTrait + StreamTrait<'a> + Send, { self.into_model().stream(db).await } @@ -329,7 +329,7 @@ where db: &'a C, ) -> Result), DbErr>> + 'b, DbErr> where - C: ConnectionTrait + StreamTrait + Send, + C: ConnectionTrait + StreamTrait<'a> + Send, { self.into_model().stream(db).await } @@ -367,7 +367,7 @@ where db: &'a C, ) -> Result), DbErr>> + 'b + Send, DbErr> where - C: ConnectionTrait + StreamTrait + Send, + C: ConnectionTrait + StreamTrait<'a> + Send, { self.into_model().stream(db).await } @@ -453,7 +453,7 @@ where db: &'a C, ) -> Result> + 'b + Send>>, DbErr> where - C: ConnectionTrait + StreamTrait + Send, + C: ConnectionTrait + StreamTrait<'a> + Send, S: 'b, S::Item: Send, { @@ -739,7 +739,7 @@ where db: &'a C, ) -> Result> + 'b + Send>>, DbErr> where - C: ConnectionTrait + StreamTrait + Send, + C: ConnectionTrait + StreamTrait<'a> + Send, S: 'b, S::Item: Send, {