pub struct Query { /* private fields */ }
Implementations§
Source§impl Query
impl Query
Sourcepub fn sql_display(&self) -> &impl Display
pub fn sql_display(&self) -> &impl Display
Display SQL query as string.
Sourcepub fn bind(self, value: impl Bind) -> Self
pub fn bind(self, value: impl Bind) -> Self
Binds value
to the next ?
in the query.
The value
, which must either implement Serialize
or be an
Identifier
, will be appropriately escaped.
All possible errors will be returned as Error::InvalidParams
during query execution (execute()
, fetch()
etc).
WARNING: This means that the query must not have any extra ?
, even if
they are in a string literal! Use ??
to have plain ?
in query.
Sourcepub fn fetch<T: Row>(self) -> Result<RowCursor<T>>
pub fn fetch<T: Row>(self) -> Result<RowCursor<T>>
Executes the query, returning a RowCursor
to obtain results.
§Example
#[derive(clickhouse::Row, serde::Deserialize)]
struct MyRow<'a> {
no: u32,
name: &'a str,
}
let mut cursor = clickhouse::Client::default()
.query("SELECT ?fields FROM some WHERE no BETWEEN 0 AND 1")
.fetch::<MyRow<'_>>()?;
while let Some(MyRow { name, no }) = cursor.next().await? {
println!("{name}: {no}");
}
Sourcepub async fn fetch_one<T>(self) -> Result<T>where
T: Row + for<'b> Deserialize<'b>,
pub async fn fetch_one<T>(self) -> Result<T>where
T: Row + for<'b> Deserialize<'b>,
Executes the query and returns just a single row.
Note that T
must be owned.
Sourcepub async fn fetch_optional<T>(self) -> Result<Option<T>>where
T: Row + for<'b> Deserialize<'b>,
pub async fn fetch_optional<T>(self) -> Result<Option<T>>where
T: Row + for<'b> Deserialize<'b>,
Executes the query and returns at most one row.
Note that T
must be owned.
Sourcepub async fn fetch_all<T>(self) -> Result<Vec<T>>where
T: Row + for<'b> Deserialize<'b>,
pub async fn fetch_all<T>(self) -> Result<Vec<T>>where
T: Row + for<'b> Deserialize<'b>,
Executes the query and returns all the generated results, collected into a Vec.
Note that T
must be owned.
Sourcepub fn fetch_bytes(self, format: impl Into<String>) -> Result<BytesCursor>
pub fn fetch_bytes(self, format: impl Into<String>) -> Result<BytesCursor>
Executes the query, returning a BytesCursor
to obtain results as raw
bytes containing data in the provided format.
Sourcepub fn with_option(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_option( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Similar to Client::with_option
, but for this particular query only.