Skip to main content

ConnQueryExt

Trait ConnQueryExt 

Source
pub trait ConnQueryExt: ConnExt {
    // Provided methods
    fn query_one<T: FromRow + Send>(
        &self,
        sql: &str,
        params: impl IntoParams + Send,
    ) -> impl Future<Output = Result<T>> + Send { ... }
    fn query_optional<T: FromRow + Send>(
        &self,
        sql: &str,
        params: impl IntoParams + Send,
    ) -> impl Future<Output = Result<Option<T>>> + Send { ... }
    fn query_all<T: FromRow + Send>(
        &self,
        sql: &str,
        params: impl IntoParams + Send,
    ) -> impl Future<Output = Result<Vec<T>>> + Send { ... }
    fn query_one_map<T: Send, F>(
        &self,
        sql: &str,
        params: impl IntoParams + Send,
        f: F,
    ) -> impl Future<Output = Result<T>> + Send
       where F: Fn(&Row) -> Result<T> + Send { ... }
    fn query_optional_map<T: Send, F>(
        &self,
        sql: &str,
        params: impl IntoParams + Send,
        f: F,
    ) -> impl Future<Output = Result<Option<T>>> + Send
       where F: Fn(&Row) -> Result<T> + Send { ... }
    fn query_all_map<T: Send, F>(
        &self,
        sql: &str,
        params: impl IntoParams + Send,
        f: F,
    ) -> impl Future<Output = Result<Vec<T>>> + Send
       where F: Fn(&Row) -> Result<T> + Send { ... }
}
Expand description

High-level query helpers built on ConnExt.

Blanket-implemented for all ConnExt types. Import this trait to use query_one, query_optional, query_all, and their _map variants.

Provided Methods§

Source

fn query_one<T: FromRow + Send>( &self, sql: &str, params: impl IntoParams + Send, ) -> impl Future<Output = Result<T>> + Send

Fetch the first row as T via FromRow.

§Errors

Returns Error::not_found if the query returns no rows.

Source

fn query_optional<T: FromRow + Send>( &self, sql: &str, params: impl IntoParams + Send, ) -> impl Future<Output = Result<Option<T>>> + Send

Fetch the first row as T via FromRow, returning None if empty.

§Errors

Returns an error if the query fails or row conversion fails.

Source

fn query_all<T: FromRow + Send>( &self, sql: &str, params: impl IntoParams + Send, ) -> impl Future<Output = Result<Vec<T>>> + Send

Fetch all rows as Vec<T> via FromRow.

§Errors

Returns an error if the query fails or any row conversion fails.

Source

fn query_one_map<T: Send, F>( &self, sql: &str, params: impl IntoParams + Send, f: F, ) -> impl Future<Output = Result<T>> + Send
where F: Fn(&Row) -> Result<T> + Send,

Fetch the first row and map it with a closure.

§Errors

Returns Error::not_found if the query returns no rows.

Source

fn query_optional_map<T: Send, F>( &self, sql: &str, params: impl IntoParams + Send, f: F, ) -> impl Future<Output = Result<Option<T>>> + Send
where F: Fn(&Row) -> Result<T> + Send,

Fetch the first row and map it with a closure, returning None if empty.

§Errors

Returns an error if the query fails or the mapping closure returns an error.

Source

fn query_all_map<T: Send, F>( &self, sql: &str, params: impl IntoParams + Send, f: F, ) -> impl Future<Output = Result<Vec<T>>> + Send
where F: Fn(&Row) -> Result<T> + Send,

Fetch all rows and map each with a closure.

§Errors

Returns an error if the query fails or any mapping closure call returns an error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§