Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support server-side parameter binding #142

Closed
slvrtrn opened this issue Sep 5, 2024 · 4 comments
Closed

Support server-side parameter binding #142

slvrtrn opened this issue Sep 5, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@slvrtrn
Copy link
Contributor

slvrtrn commented Sep 5, 2024

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?;
@mshustov
Copy link
Member

what about

client
    .query("SELECT plus({val1: Int32}, {val2: Int32}) AS result")
    .with_param("val1", 42)
    .with_param("val2", 144)
    .fetch_one::<i32>()
    .await?;

@slvrtrn
Copy link
Contributor Author

slvrtrn commented Sep 10, 2024

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.

@serprex
Copy link
Member

serprex commented Sep 11, 2024

Can create generic method over serializable types

serprex added a commit that referenced this issue Sep 24, 2024
@serprex serprex self-assigned this Sep 24, 2024
serprex added a commit that referenced this issue Sep 24, 2024
serprex added a commit that referenced this issue Sep 24, 2024
serprex added a commit that referenced this issue Sep 24, 2024
serprex added a commit that referenced this issue Sep 24, 2024
@slvrtrn slvrtrn mentioned this issue Sep 24, 2024
serprex added a commit that referenced this issue Sep 24, 2024
serprex added a commit that referenced this issue Sep 24, 2024
serprex added a commit that referenced this issue Oct 2, 2024
serprex added a commit that referenced this issue Oct 2, 2024
serprex added a commit that referenced this issue Oct 2, 2024
serprex added a commit that referenced this issue Oct 2, 2024
serprex added a commit that referenced this issue Nov 7, 2024
serprex added a commit that referenced this issue Nov 19, 2024
@mshustov
Copy link
Member

mshustov commented Dec 3, 2024

@serprex closed by #159?

@serprex serprex closed this as completed Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants