[][src]Struct tiberius::QueryResult

pub struct QueryResult<'a> { /* fields omitted */ }

A set of Streams of Rows resulting from a SELECT query. The QueryResult needs to be polled empty before sending another query to the Client, failing to do so causes a flush before the next query, slowing it down in an undeterministic way.

If executing multiple queries, the resulting streams will be split. Before polling the next results, a call to next_resultset with a response of true is needed. When the next_resultset returns false the results should not be polled anymore.

Example

let mut stream = client
    .query(
        "SELECT @P1 AS first; SELECT @P2 AS second",
        &[&1i32, &2i32],
    )
    .await?;

// Result of `SELECT 1`. Taking the `Stream` by reference, allowing us to
// poll it later again. We fetch the value with column index.
let first_result: Vec<Option<i32>> = stream
    .by_ref()
    .map_ok(|x| x.get::<i32, _>(0))
    .try_collect()
    .await?;

assert_eq!(Some(1), first_result[0]);

// Allows us to poll more results.
assert!(stream.next_resultset());

// Result of `SELECT 2`, this time fetching with the column name.
let second_result: Vec<Option<i32>> = stream
    .by_ref()
    .map_ok(|x| x.get::<i32, _>("second"))
    .try_collect()
    .await?;

assert_eq!(Some(2), second_result[0]);

// No more results left. We should not poll again.
assert!(!stream.next_resultset());

Implementations

impl<'a> QueryResult<'a>[src]

pub fn columns(&'a self) -> Option<&[Column]>[src]

Names of the columns of the current resultset. Order is the same as the order of columns in the rows. Needs to be called separately for every result set. None if query could not result anything.

Example

let mut result_set = client
    .query(
        "SELECT 1 AS foo; SELECT 2 AS bar",
        &[&1i32, &2i32, &3i32],
    )
    .await?;

let columns = result_set.columns().unwrap();
assert_eq!("foo", columns[0].name());

result_set.next_resultset();

let columns = result_set.columns().unwrap();
assert_eq!("bar", columns[0].name());

pub fn next_resultset(&mut self) -> bool[src]

Returns true if stream has more result sets available. Must be called before polling again to get results from the next query.

pub async fn into_results(__arg0: Self) -> Result<Vec<Vec<Row>>>[src]

Collects results from all queries in the stream into memory in the order of querying.

pub async fn into_first_result(self) -> Result<Vec<Row>>[src]

Collects the output of the first query, dropping any further results.

pub async fn into_row(self) -> Result<Option<Row>>[src]

Collects the first row from the output of the first query, dropping any further rows.

Trait Implementations

impl<'a> Debug for QueryResult<'a>[src]

impl<'a> Stream for QueryResult<'a>[src]

type Item = Result<Row>

Values yielded by the stream.

Auto Trait Implementations

impl<'a> !RefUnwindSafe for QueryResult<'a>

impl<'a> Send for QueryResult<'a>

impl<'a> !Sync for QueryResult<'a>

impl<'a> Unpin for QueryResult<'a>

impl<'a> !UnwindSafe for QueryResult<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<St> StreamExt for St where
    St: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,