diff --git a/tests/postgres-macros.rs b/tests/postgres-macros.rs index 0d6e89d5..1ed88811 100644 --- a/tests/postgres-macros.rs +++ b/tests/postgres-macros.rs @@ -1,6 +1,8 @@ use sqlx::Postgres; use sqlx_test::new; +use futures::TryStreamExt; + #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] async fn test_query() -> anyhow::Result<()> { @@ -244,3 +246,21 @@ async fn test_array_from_slice() -> anyhow::Result<()> { Ok(()) } + +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] +async fn fetch_is_usable_issue_224() -> anyhow::Result<()> { + // ensures that the stream returned by `query::Map::fetch()` is usable with `TryStreamExt` + let mut conn = new::().await?; + + let mut stream = + sqlx::query!("select * from generate_series(1, 3) as series(num);").fetch(&mut conn); + + // `num` is generated by a function so we can't assume it's non-null + assert_eq!(stream.try_next().await?.unwrap().num, Some(1)); + assert_eq!(stream.try_next().await?.unwrap().num, Some(2)); + assert_eq!(stream.try_next().await?.unwrap().num, Some(3)); + assert!(stream.try_next().await?.is_none()); + + Ok(()) +}