Skip to content

Commit 5922a7c

Browse files
committed
refactor(odbc): streamline fetch_many implementation in Executor
This commit updates the fetch_many method in the Executor implementation for OdbcConnection to utilize into_future and then, simplifying the handling of query results and enhancing code clarity.
1 parent 19e66fc commit 5922a7c

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

sqlx-core/src/odbc/connection/executor.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::odbc::{Odbc, OdbcConnection, OdbcQueryResult, OdbcRow, OdbcStatement,
55
use either::Either;
66
use futures_core::future::BoxFuture;
77
use futures_core::stream::BoxStream;
8-
use futures_util::TryStreamExt;
8+
use futures_util::{future, FutureExt, StreamExt};
99

1010
// run method removed; fetch_many implements streaming directly
1111

@@ -32,15 +32,12 @@ impl<'c> Executor<'c> for &'c mut OdbcConnection {
3232
'c: 'e,
3333
E: Execute<'q, Self::Database> + 'q,
3434
{
35-
let mut s = self.fetch_many(query);
36-
Box::pin(async move {
37-
while let Some(v) = s.try_next().await? {
38-
if let Either::Right(r) = v {
39-
return Ok(Some(r));
40-
}
41-
}
42-
Ok(None)
43-
})
35+
Box::pin(self.fetch_many(query).into_future().then(|(v, _)| match v {
36+
Some(Ok(Either::Right(r))) => future::ok(Some(r)),
37+
Some(Ok(Either::Left(_))) => future::ok(None),
38+
Some(Err(e)) => future::err(e),
39+
None => future::ok(None),
40+
}))
4441
}
4542

4643
fn prepare_with<'e, 'q: 'e>(

0 commit comments

Comments
 (0)