Skip to content

Commit

Permalink
[not for upstream] Revert "use GAT to elide StreamTrait lifetime (Sea…
Browse files Browse the repository at this point in the history
…QL#1161)"

To reduce MSRV so Attic builds with nixpkgs 22.11 that has
Rust 1.64. This workaround will be removed when 23.05 becomes
stable.

This reverts commit 9d25ee9.
  • Loading branch information
zhaofengli committed Jan 16, 2023
1 parent 64fc70a commit 8b70e53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
10 changes: 4 additions & 6 deletions src/database/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = Result<QueryResult, DbErr>> + Send
where
Self: 'a;
type Stream: Stream<Item = Result<QueryResult, DbErr>> + Send;

/// Execute a [Statement] and return a stream of results
fn stream<'a>(
fn stream(
&'a self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream<'a>, DbErr>> + 'a + Send>>;
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, DbErr>> + 'a + Send>>;
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
8 changes: 4 additions & 4 deletions src/database/db_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Future<Output = Result<Self::Stream<'a>, DbErr>> + 'a + Send>> {
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, DbErr>> + 'a + Send>> {
Box::pin(async move {
Ok(match self {
#[cfg(feature = "sqlx-mysql")]
Expand Down
10 changes: 6 additions & 4 deletions src/database/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Future<Output = Result<Self::Stream<'a>, DbErr>> + 'a + Send>> {
) -> Pin<Box<dyn Future<Output = Result<Self::Stream, DbErr>> + 'a + Send>> {
Box::pin(async move {
let conn = self.conn.lock().await;
Ok(crate::TransactionStream::build(
Expand Down
10 changes: 5 additions & 5 deletions src/executor/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ where
db: &'a C,
) -> Result<impl Stream<Item = Result<E::Model, DbErr>> + 'b + Send, DbErr>
where
C: ConnectionTrait + StreamTrait + Send,
C: ConnectionTrait + StreamTrait<'a> + Send,
{
self.into_model().stream(db).await
}
Expand Down Expand Up @@ -329,7 +329,7 @@ where
db: &'a C,
) -> Result<impl Stream<Item = Result<(E::Model, Option<F::Model>), DbErr>> + 'b, DbErr>
where
C: ConnectionTrait + StreamTrait + Send,
C: ConnectionTrait + StreamTrait<'a> + Send,
{
self.into_model().stream(db).await
}
Expand Down Expand Up @@ -367,7 +367,7 @@ where
db: &'a C,
) -> Result<impl Stream<Item = Result<(E::Model, Option<F::Model>), DbErr>> + 'b + Send, DbErr>
where
C: ConnectionTrait + StreamTrait + Send,
C: ConnectionTrait + StreamTrait<'a> + Send,
{
self.into_model().stream(db).await
}
Expand Down Expand Up @@ -453,7 +453,7 @@ where
db: &'a C,
) -> Result<Pin<Box<dyn Stream<Item = Result<S::Item, DbErr>> + 'b + Send>>, DbErr>
where
C: ConnectionTrait + StreamTrait + Send,
C: ConnectionTrait + StreamTrait<'a> + Send,
S: 'b,
S::Item: Send,
{
Expand Down Expand Up @@ -739,7 +739,7 @@ where
db: &'a C,
) -> Result<Pin<Box<dyn Stream<Item = Result<S::Item, DbErr>> + 'b + Send>>, DbErr>
where
C: ConnectionTrait + StreamTrait + Send,
C: ConnectionTrait + StreamTrait<'a> + Send,
S: 'b,
S::Item: Send,
{
Expand Down

0 comments on commit 8b70e53

Please sign in to comment.