[−][src]Struct postgres_query::Query
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:
- use the provided methods:
execute,fetch,query, etc. - use the
sqlandparametersfields as arguments to the standardClientmethods
#[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]
C: GenericClient + Sync,
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]
T: FromSqlRow,
C: GenericClient + Sync,
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]
T: FromSqlRow,
C: GenericClient + Sync,
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]
&'_ self,
client: &'_ C
) -> Result<impl Stream<Item = Result<T>>> where
T: FromSqlRow,
C: GenericClient + Sync,
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]
C: GenericClient + Sync,
Execute this query and return the resulting rows.
pub async fn query_one<'_, '_, C>(&'_ self, client: &'_ C) -> Result<Row> where
C: GenericClient + Sync, [src]
C: GenericClient + Sync,
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]
&'_ self,
client: &'_ C
) -> Result<impl Stream<Item = Result<Row>>> where
C: GenericClient + Sync,
Execute this query and return the resulting values as an asynchronous stream of values.
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,