pub struct Query<'a> { /* private fields */ }Expand description
A query builder created by Database::query or DatabaseRef::query.
Configure parameters, settings, and an optional query ID, then run it with a
fetch method.
Implementations§
Source§impl<'a> Query<'a>
impl<'a> Query<'a>
Sourcepub fn param(self, name: impl Into<String>, value: impl Into<Param>) -> Self
pub fn param(self, name: impl Into<String>, value: impl Into<Param>) -> Self
Binds value to the {name:Type} parameter placeholder. See Param
for supported types.
Sourcepub fn setting(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn setting(self, name: impl Into<String>, value: impl Into<String>) -> Self
Sets a ClickHouse query setting such as max_execution_time. Unknown
settings are reported as server errors.
Sourcepub fn query_id(self, id: impl Into<String>) -> Self
pub fn query_id(self, id: impl Into<String>) -> Self
Sets an explicit server-side query ID (visible in system.query_log)
instead of letting ClickHouse generate one.
Sourcepub async fn fetch<T: FromRow>(self) -> Result<RowStream<T>, Error>
pub async fn fetch<T: FromRow>(self) -> Result<RowStream<T>, Error>
Runs the query and streams rows as they arrive, decoding each as T
(either Row or a serde::Deserialize type).
async fn scan() -> Result<u64, Error> {
let mut rows = EVENTS.read().query("SELECT id FROM events").fetch::<u64>().await?;
let mut sum = 0;
while let Some(id) = rows.next().await {
sum += id?;
}
Ok(sum)
}Sourcepub async fn fetch_all<T: FromRow>(self) -> Result<Vec<T>, Error>
pub async fn fetch_all<T: FromRow>(self) -> Result<Vec<T>, Error>
Runs the query and collects all rows decoded as T.
Sourcepub async fn fetch_one<T: FromRow>(self) -> Result<T, Error>
pub async fn fetch_one<T: FromRow>(self) -> Result<T, Error>
Runs the query and returns its single row decoded as T.
Returns Error::NoRows if no rows are returned, or
Error::TooManyRows if more than one row is returned.
Sourcepub async fn fetch_optional<T: FromRow>(self) -> Result<Option<T>, Error>
pub async fn fetch_optional<T: FromRow>(self) -> Result<Option<T>, Error>
Runs the query and returns at most one row decoded as T.
Returns Error::TooManyRows if more than one row is returned.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Query<'a>
impl<'a> !UnwindSafe for Query<'a>
impl<'a> Forget for Query<'a>
impl<'a> Freeze for Query<'a>
impl<'a> Move for Query<'a>
impl<'a> Send for Query<'a>
impl<'a> Sync for Query<'a>
impl<'a> Unpin for Query<'a>
impl<'a> UnsafeUnpin for Query<'a>where
&'a Database: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<(String, Value)>: UnsafeUnpin,
PhantomData<(String, String)>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request