Struct duckdb::Rows [−][src]
pub struct Rows<'stmt> { /* fields omitted */ }
Expand description
An handle for the resulting rows of a query.
Implementations
Attempt to get the next row from the query. Returns Ok(Some(Row))
if
there is another row, Err(...)
if there was an error
getting the next row, and Ok(None)
if all rows have been retrieved.
Note
This interface is not compatible with Rust’s Iterator
trait, because
the lifetime of the returned row is tied to the lifetime of self
.
This is a fallible “streaming iterator”. For a more natural interface,
consider using query_map
or
query_and_then
instead, which
return types that implement Iterator
.
Map over this Rows
, converting it to a Map
, which
implements FallibleIterator
.
use fallible_iterator::FallibleIterator;
fn query(stmt: &mut Statement) -> Result<Vec<i64>> {
let rows = stmt.query([])?;
rows.map(|r| r.get(0)).collect()
}
pub fn mapped<F, B>(self, f: F) -> MappedRows<'stmt, F>ⓘNotable traits for MappedRows<'_, F>impl<T, F> Iterator for MappedRows<'_, F> where
F: FnMut(&Row<'_>) -> Result<T>, type Item = Result<T>;
where
F: FnMut(&Row<'_>) -> Result<B>,
pub fn mapped<F, B>(self, f: F) -> MappedRows<'stmt, F>ⓘNotable traits for MappedRows<'_, F>impl<T, F> Iterator for MappedRows<'_, F> where
F: FnMut(&Row<'_>) -> Result<T>, type Item = Result<T>;
where
F: FnMut(&Row<'_>) -> Result<B>,
impl<T, F> Iterator for MappedRows<'_, F> where
F: FnMut(&Row<'_>) -> Result<T>, type Item = Result<T>;
Map over this Rows
, converting it to a MappedRows
, which
implements Iterator
.
Map over this Rows
with a fallible function, converting it to a
AndThenRows
, which implements Iterator
(instead of
FallibleStreamingIterator
).
Trait Implementations
FallibleStreamingIterator
differs from the standard library’s Iterator
in two ways:
- each call to
next
(sqlite3_step) can fail. - returned
Row
is valid untilnext
is called again orStatement
is reset or finalized.
While these iterators cannot be used with Rust for
loops, while let
loops offer a similar level of ergonomics:
fn query(stmt: &mut Statement) -> Result<()> {
let mut rows = stmt.query([])?;
while let Some(row) = rows.next()? {
// scan columns value
}
Ok(())
}
Advances the iterator, returning the next element. Read more
Returns bounds on the number of remaining elements in the iterator.
Determines if all elements of the iterator satisfy a predicate.
Determines if any elements of the iterator satisfy a predicate.
Returns the number of remaining elements in the iterator.
Returns an iterator which filters elements by a predicate.
Returns the first element of the iterator which satisfies a predicate.
Calls a closure on each element of an iterator.
Returns an iterator which is well-behaved at the beginning and end of iteration.
Returns an iterator which applies a transform to elements.
Returns an iterator which applies a transform to elements. Read more
Returns an iterator that applies a transform to errors.
Returns the nth
element of the iterator.
Returns the position of the first element matching a predicate.
Returns an iterator which skips the first sequence of elements matching a predicate.
Returns an iterator which only returns the first n
elements.