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

feat: add Parameterized Queries #597

Merged
merged 9 commits into from
Feb 20, 2025
Merged

feat: add Parameterized Queries #597

merged 9 commits into from
Feb 20, 2025

Conversation

sundy-li
Copy link
Member

@sundy-li sundy-li commented Feb 19, 2025

fixes #583

Currently, we support ? , $1, :name three kinds of parameter binding style.

rust example:

let row = conn
    .query_row("SELECT $1, $2, $3, $4", (3, false, 4, "55"))
    .await
    .unwrap();

let params = params! {a => 3, b => false, c => 4, d => "55"};
let row = conn
    .query_row("SELECT :a, :b, :c, :d", params)
    .await
    .unwrap();

let row = conn
    .query_row("SELECT ?, ?, ?, ?", (3, false, 4, "55"))
    .await
    .unwrap();

nodejs example with optional params arg:

const row = await this.conn.queryRow("SELECT 1, 2");
const row = await this.conn.queryRow("SELECT ?, ?", params = [1.11, 2.22]);
const row = await this.conn.queryRow("SELECT $1, $2", params = [1.11, 2.22]);
const row = await this.conn.queryRow("SELECT :a, :b", params =  {  a: 1.11, b:2.22  });

python example with optional params arg:

row = await context.conn.query_row("select ?", "xyz")
row = await context.conn.query_row("select $1", params = ("xyz"))
row = await context.conn.query_row("select $1, $2)",  ["xyz", 2])
row = await context.conn.query_row("select ?, ?)", params = ("xyz", 2))
row = await context.conn.query_row("SELECT :a, :b", params =  {  a: 1.11, b:2.22  })

and a format_sql function to generate final sql

@sundy-li sundy-li requested a review from everpcpc February 19, 2025 23:43
@sundy-li sundy-li marked this pull request as ready for review February 19, 2025 23:44
@sundy-li
Copy link
Member Author

cc @Shanmugavel-J @rad-pat

@sundy-li sundy-li requested a review from b41sh February 19, 2025 23:46
@sundy-li sundy-li merged commit 399d6a1 into main Feb 20, 2025
32 checks passed
@sundy-li sundy-li deleted the tpch-doc branch February 20, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Support for Parameterized Queries in databend-driver
2 participants