postgres/
row_iter.rs

1use crate::connection::ConnectionRef;
2use fallible_iterator::FallibleIterator;
3use futures_util::StreamExt;
4use std::pin::Pin;
5use tokio_postgres::{Error, Row, RowStream};
6
7/// The iterator returned by `query_raw`.
8pub struct RowIter<'a> {
9    connection: ConnectionRef<'a>,
10    it: Pin<Box<RowStream>>,
11}
12
13impl<'a> RowIter<'a> {
14    pub(crate) fn new(connection: ConnectionRef<'a>, stream: RowStream) -> RowIter<'a> {
15        RowIter {
16            connection,
17            it: Box::pin(stream),
18        }
19    }
20
21    /// Returns the number of rows affected by the query.
22    ///
23    /// This function will return `None` until the iterator has been exhausted.
24    pub fn rows_affected(&self) -> Option<u64> {
25        self.it.rows_affected()
26    }
27}
28
29impl FallibleIterator for RowIter<'_> {
30    type Item = Row;
31    type Error = Error;
32
33    fn next(&mut self) -> Result<Option<Row>, Error> {
34        let it = &mut self.it;
35        self.connection
36            .block_on(async { it.next().await.transpose() })
37    }
38}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy