From 09324db1b054fb47863c275687aa4ea0f0494176 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 16 Oct 2021 00:20:27 +0800 Subject: [PATCH] Stream example --- src/database/mock.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/database/mock.rs b/src/database/mock.rs index fd8dbd25..44522944 100644 --- a/src/database/mock.rs +++ b/src/database/mock.rs @@ -527,6 +527,24 @@ mod tests { Ok(()) } + #[smol_potat::test] + async fn test_stream_2() -> Result<(), DbErr> { + use fruit::Entity as Fruit; + use futures::TryStreamExt; + + let db = MockDatabase::new(DbBackend::Postgres) + .append_query_results(vec![Vec::::new()]) + .into_connection(); + + let mut stream = Fruit::find().stream(&db).await?; + + while let Some(item) = stream.try_next().await? { + let _item: fruit::ActiveModel = item.into(); + } + + Ok(()) + } + #[smol_potat::test] async fn test_stream_in_transaction() -> Result<(), DbErr> { use futures::TryStreamExt; @@ -556,7 +574,7 @@ mod tests { assert_eq!(stream.try_next().await?, None); - // stream will be dropped end of scope OR std::mem::drop(stream); + // stream will be dropped end of scope } txn.commit().await?;