clickhouse.rs
clickhouse.rs copied to clipboard
Support server-side parameter binding
See the docs.
For example:
SELECT plus({val1: Int32}, {val2: Int32}) AS result
We already have .bind, though, for client-side substitutions; so maybe it can be done as
client
.query("SELECT plus({val1: Int32}, {val2: Int32}) AS result")
.with_param(42)
.with_param(144)
.fetch_one::<i32>()
.await?;
Theoretically, we can even do something like this as well:
client
.query("SELECT plus({?}, {?}) AS result")
.with_param("val1", 42)
.with_param("val2", 144)
.fetch_one::<i32>()
.await?;
what about
client
.query("SELECT plus({val1: Int32}, {val2: Int32}) AS result")
.with_param("val1", 42)
.with_param("val2", 144)
.fetch_one::<i32>()
.await?;
It actually works now as:
use clickhouse::{error::Result, Client};
#[tokio::main]
async fn main() -> Result<()> {
let client = Client::default()
.with_url("http://localhost:8123");
let result = client
.query("SELECT plus({val1: Int32}, {val2: Int32}) AS result")
.with_option("param_val1", "42")
.with_option("param_val2", "144")
.fetch_one::<u64>()
.await?;
println!("Result: {result:?}");
Ok(())
}
But the user has to (properly) serialize the values on the application side.
Can create generic method over serializable types
@serprex closed by https://github.com/ClickHouse/clickhouse-rs/pull/159?