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§
Sourcefn query_one<T: FromRow + Send>(
&self,
sql: &str,
params: impl IntoParams + Send,
) -> impl Future<Output = Result<T>> + Send
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.
Sourcefn query_optional<T: FromRow + Send>(
&self,
sql: &str,
params: impl IntoParams + Send,
) -> impl Future<Output = Result<Option<T>>> + Send
fn query_optional<T: FromRow + Send>( &self, sql: &str, params: impl IntoParams + Send, ) -> impl Future<Output = Result<Option<T>>> + Send
Sourcefn query_all<T: FromRow + Send>(
&self,
sql: &str,
params: impl IntoParams + Send,
) -> impl Future<Output = Result<Vec<T>>> + Send
fn query_all<T: FromRow + Send>( &self, sql: &str, params: impl IntoParams + Send, ) -> impl Future<Output = Result<Vec<T>>> + Send
Sourcefn query_one_map<T: Send, F>(
&self,
sql: &str,
params: impl IntoParams + Send,
f: F,
) -> impl Future<Output = Result<T>> + Send
fn query_one_map<T: Send, F>( &self, sql: &str, params: impl IntoParams + Send, f: F, ) -> impl Future<Output = Result<T>> + Send
Fetch the first row and map it with a closure.
§Errors
Returns Error::not_found if the query returns no rows.
Sourcefn query_optional_map<T: Send, F>(
&self,
sql: &str,
params: impl IntoParams + Send,
f: F,
) -> impl Future<Output = Result<Option<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
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.
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.