[][src]Struct sqlx::Query

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

Dynamic SQL query with bind parameters. Returned by [query].

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

Methods

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

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.

pub fn fetch<'e, E>(
    self,
    executor: &'e mut E
) -> Pin<Box<dyn Stream<Item = Result<<DB as Database>::Row, Error>> + 'e + Send>> 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<<DB as Database>::Row>, 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<<DB as Database>::Row>, 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<<DB as Database>::Row, Error> where
    E: Executor<Database = DB>, 
[src]

Execute a query which should return exactly 1 row.

impl<'q, DB> Query<'q, DB, <DB as Database>::Arguments> where
    DB: Database
[src]

pub fn bind<T>(self, value: T) -> Query<'q, DB, <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, T> RefUnwindSafe for Query<'q, DB, T> where
    DB: RefUnwindSafe,
    T: RefUnwindSafe

impl<'q, DB, T> Send for Query<'q, DB, T> where
    DB: Send,
    T: Send

impl<'q, DB, T> Sync for Query<'q, DB, T> where
    DB: Sync,
    T: Sync

impl<'q, DB, T> Unpin for Query<'q, DB, T> where
    DB: Unpin,
    T: Unpin

impl<'q, DB, T> UnwindSafe for Query<'q, DB, T> where
    DB: UnwindSafe,
    T: 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> Same<T> for T

type Output = T

Should always be Self

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<V, T> VZip<V> for T where
    V: MultiLane<T>,