[][src]Struct sqlx::QueryAs

pub struct QueryAs<'q, DB, R, P = <DB as Database>::Arguments> where
    DB: Database
{ /* fields omitted */ }

SQL query with bind parameters, which maps rows to an explicit output type.

Returned by [query_as] and query! et al.

The methods on this struct should be passed a reference to crate::Pool or one of the connection types.

Methods

impl<'_, DB, P> QueryAs<'_, DB, (), P> where
    DB: Database,
    P: IntoArguments<DB> + Send
[src]

The result of query! for SQL queries that does not return output.

pub async fn execute<E>(self, executor: &'_ mut E) -> Result<u64, Error> where
    E: Executor<Database = DB>, 
[src]

Execute the query for its side-effects.

Returns the number of rows affected, or 0 if not applicable.

impl<'q, DB, R, P> QueryAs<'q, DB, R, P> where
    DB: Database,
    P: IntoArguments<DB> + Send,
    R: Send + 'q, 
[src]

pub fn fetch<'e, E>(
    self,
    executor: &'e mut E
) -> impl Stream<Item = Result<R, Error>> + 'e where
    'q: 'e,
    E: Executor<Database = DB>, 
[src]

Execute the query, returning the rows as a futures Stream.

Use [fetch_all] if you want a Vec instead.

pub async fn fetch_all<E>(self, executor: &'_ mut E) -> Result<Vec<R>, Error> where
    E: Executor<Database = DB>, 
[src]

Execute the query and get all rows from the result as a Vec.

pub async fn fetch_optional<E>(
    self,
    executor: &'_ mut E
) -> Result<Option<R>, Error> where
    E: Executor<Database = DB>, 
[src]

Execute a query which should return either 0 or 1 rows.

Returns crate::Error::FoundMoreThanOne if more than 1 row is returned. Use .fetch().try_next() if you just want one row.

pub async fn fetch_one<E>(self, executor: &'_ mut E) -> Result<R, Error> where
    E: Executor<Database = DB>, 
[src]

Execute a query which should return exactly 1 row.

impl<'q, DB, R> QueryAs<'q, DB, R, <DB as Database>::Arguments> where
    DB: Database,
    <DB as Database>::Arguments: Arguments,
    <<DB as Database>::Arguments as Arguments>::Database == DB, 
[src]

pub fn bind<T>(
    self,
    value: T
) -> QueryAs<'q, DB, R, <DB as Database>::Arguments> where
    DB: HasSqlType<T>,
    T: Encode<DB>, 
[src]

Bind a value for use with this SQL query.

Logic Safety

This function should be used with care, as SQLx cannot validate that the value is of the right type nor can it validate that you have passed the correct number of parameters.

Auto Trait Implementations

impl<'q, DB, R, P> RefUnwindSafe for QueryAs<'q, DB, R, P> where
    P: RefUnwindSafe

impl<'q, DB, R, P> Send for QueryAs<'q, DB, R, P> where
    P: Send

impl<'q, DB, R, P> Sync for QueryAs<'q, DB, R, P> where
    P: Sync

impl<'q, DB, R, P> Unpin for QueryAs<'q, DB, R, P> where
    P: Unpin

impl<'q, DB, R, P> UnwindSafe for QueryAs<'q, DB, R, P> where
    P: UnwindSafe

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, DB> HasSqlType<&'_ T> for DB where
    DB: HasSqlType<T>,
    T: ?Sized
[src]

impl<T, DB> HasSqlType<Option<T>> for DB where
    DB: HasSqlType<T>, 
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[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.