[][src]Struct postgres_query::Query

pub struct Query<'a> {
    pub sql: &'static str,
    pub parameters: Vec<&'a (dyn ToSql + Sync)>,
}

A static query with dynamic parameters.

Usage

The preferred way of constructing a Query is by using the query! macro.

When executing the query you have two options, either:

  1. use the provided methods: execute, fetch, query, etc.
  2. use the sql and parameters fields as arguments to the standard Client methods
#[derive(FromSqlRow)]
struct Person {
    age: i32,
    name: String,
}

let client: Client = connect(/* ... */);
let query = query!("SELECT age, name FROM people");

// Option 1
let people: Vec<Person> = query.fetch(&client).await?;

// Option 2
let rows: Vec<Row> = client.query(query.sql, &query.parameters).await?;
let people: Vec<Person> = Person::from_row_multi(&rows)?;

Fields

sql: &'static strparameters: Vec<&'a (dyn ToSql + Sync)>

Methods

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

pub async fn execute<'_, '_, C>(&'_ self, client: &'_ C) -> Result<u64> where
    C: GenericClient + Sync
[src]

Execute this query and return the number of affected rows.

pub async fn fetch<'_, '_, T, C>(&'_ self, client: &'_ C) -> Result<Vec<T>> where
    T: FromSqlRow,
    C: GenericClient + Sync
[src]

Execute this query and return the resulting values.

pub async fn fetch_one<'_, '_, T, C>(&'_ self, client: &'_ C) -> Result<T> where
    T: FromSqlRow,
    C: GenericClient + Sync
[src]

Execute this query and return the resulting value. This method will return an error if, not exactly one row was returned by the query.

pub async fn fetch_streaming<'_, '_, T, C>(
    &'_ self,
    client: &'_ C
) -> Result<impl Stream<Item = Result<T>>> where
    T: FromSqlRow,
    C: GenericClient + Sync
[src]

Execute this query and return the resulting values as an asynchronous stream of values.

pub async fn query<'_, '_, C>(&'_ self, client: &'_ C) -> Result<Vec<Row>> where
    C: GenericClient + Sync
[src]

Execute this query and return the resulting rows.

pub async fn query_one<'_, '_, C>(&'_ self, client: &'_ C) -> Result<Row> where
    C: GenericClient + Sync
[src]

Execute this query and return the resulting row. This method will return an error if, not exactly one row was returned by the query.

pub async fn query_streaming<'_, '_, C>(
    &'_ self,
    client: &'_ C
) -> Result<impl Stream<Item = Result<Row>>> where
    C: GenericClient + Sync
[src]

Execute this query and return the resulting values as an asynchronous stream of values.

Trait Implementations

impl<'a> Clone for Query<'a>[src]

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

Auto Trait Implementations

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

impl<'a> Send for Query<'a>

impl<'a> Sync for Query<'a>

impl<'a> Unpin for Query<'a>

impl<'a> !UnwindSafe for Query<'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> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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>,