Streaming for MockConnection
This commit is contained in:
parent
eb87b7c2ce
commit
018f7dd19f
@ -315,4 +315,35 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(db.into_transaction_log(), vec![]);
|
assert_eq!(db.into_transaction_log(), vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[smol_potat::test]
|
||||||
|
async fn test_stream_1() -> Result<(), DbErr> {
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
|
let apple = fruit::Model {
|
||||||
|
id: 1,
|
||||||
|
name: "Apple".to_owned(),
|
||||||
|
cake_id: Some(1),
|
||||||
|
};
|
||||||
|
|
||||||
|
let orange = fruit::Model {
|
||||||
|
id: 2,
|
||||||
|
name: "orange".to_owned(),
|
||||||
|
cake_id: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let db = MockDatabase::new(DbBackend::Postgres)
|
||||||
|
.append_query_results(vec![vec![apple.clone(), orange.clone()]])
|
||||||
|
.into_connection();
|
||||||
|
|
||||||
|
let mut stream = fruit::Entity::find().stream(&db).await?;
|
||||||
|
|
||||||
|
assert_eq!(stream.try_next().await?, Some(apple));
|
||||||
|
|
||||||
|
assert_eq!(stream.try_next().await?, Some(orange));
|
||||||
|
|
||||||
|
assert_eq!(stream.try_next().await?, None);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,9 @@ use crate::{
|
|||||||
ModelTrait, Paginator, PrimaryKeyToColumn, QueryResult, Select, SelectA, SelectB, SelectTwo,
|
ModelTrait, Paginator, PrimaryKeyToColumn, QueryResult, Select, SelectA, SelectB, SelectTwo,
|
||||||
SelectTwoMany, Statement, TryGetableMany,
|
SelectTwoMany, Statement, TryGetableMany,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "sqlx-dep")]
|
|
||||||
use futures::{Stream, TryStreamExt};
|
use futures::{Stream, TryStreamExt};
|
||||||
use sea_query::SelectStatement;
|
use sea_query::SelectStatement;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
#[cfg(feature = "sqlx-dep")]
|
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -252,7 +250,6 @@ where
|
|||||||
self.into_model().all(db).await
|
self.into_model().all(db).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sqlx-dep")]
|
|
||||||
pub async fn stream<'a: 'b, 'b, C>(
|
pub async fn stream<'a: 'b, 'b, C>(
|
||||||
self,
|
self,
|
||||||
db: &'a C,
|
db: &'a C,
|
||||||
@ -320,7 +317,6 @@ where
|
|||||||
self.into_model().all(db).await
|
self.into_model().all(db).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sqlx-dep")]
|
|
||||||
pub async fn stream<'a: 'b, 'b, C>(
|
pub async fn stream<'a: 'b, 'b, C>(
|
||||||
self,
|
self,
|
||||||
db: &'a C,
|
db: &'a C,
|
||||||
@ -381,7 +377,6 @@ where
|
|||||||
self.into_model().one(db).await
|
self.into_model().one(db).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sqlx-dep")]
|
|
||||||
pub async fn stream<'a: 'b, 'b, C>(
|
pub async fn stream<'a: 'b, 'b, C>(
|
||||||
self,
|
self,
|
||||||
db: &'a C,
|
db: &'a C,
|
||||||
@ -456,7 +451,6 @@ where
|
|||||||
Ok(models)
|
Ok(models)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sqlx-dep")]
|
|
||||||
pub async fn stream<'a: 'b, 'b, C>(
|
pub async fn stream<'a: 'b, 'b, C>(
|
||||||
self,
|
self,
|
||||||
db: &'a C,
|
db: &'a C,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user