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>
pub async fn fetch_one<T>(self) -> Result<T>
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>>
pub async fn fetch_optional<T>(self) -> Result<Option<T>>
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>>
pub async fn fetch_all<T>(self) -> Result<Vec<T>>
Executes the query and returns all the generated results, collected into a Vec.
Note that T must be owned.
Sourcepub fn fetch_rows(self) -> Result<DataRowCursor>
Available on crate feature sea-ql only.
pub fn fetch_rows(self) -> Result<DataRowCursor>
sea-ql only.Executes the query, returning a DataRowCursor to obtain dynamically-typed results.
Each row is decoded into a crate::DataRow containing a sea_query::Value
for every column, using the RowBinaryWithNamesAndTypes format so that type
information is always available.
§Example
let mut cursor = client
.query("SELECT number, toString(number) AS s FROM system.numbers LIMIT 3")
.fetch_rows()?;
while let Some(row) = cursor.next().await? {
for (col, val) in row.column_names.iter().zip(&row.values) {
println!("{col}: {val:?}");
}
}Sourcepub fn fetch_bytes(self, format: impl AsRef<str>) -> Result<BytesCursor>
pub fn fetch_bytes(self, format: impl AsRef<str>) -> Result<BytesCursor>
Executes the query, returning a BytesCursor to obtain results as raw
bytes containing data in the provided format.
Sourcepub fn with_roles(
self,
roles: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_roles( self, roles: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Configure the roles to use when executing this query.
Overrides any roles previously set by this method, Query::with_option,
Client::with_roles or Client::with_option.
An empty iterator may be passed to clear the set roles.
Sourcepub fn with_default_roles(self) -> Self
pub fn with_default_roles(self) -> Self
Clear any explicit roles previously set on this Query or inherited from Client.
Overrides any roles previously set by Query::with_roles, Query::with_option,
Client::with_roles or Client::with_option.
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.