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

SQL interpolation #15

Closed
trevyn opened this issue Mar 9, 2021 · 3 comments
Closed

SQL interpolation #15

trevyn opened this issue Mar 9, 2021 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@trevyn
Copy link
Owner

trevyn commented Mar 9, 2021

Instead of

let new_name = "Joey";
execute!("UPDATE person SET age = ?, name = ? WHERE name = ?", 18, new_name, "Joe")?;

we may wish to do something like

let new_name = "Joey";
execute!(r#"UPDATE person SET age = {18}, name = {new_name} WHERE name = {"Joe"}"#)?;

or, perhaps easier to implement properly,

let new_name = "Joey";
execute!("UPDATE person SET age = " 18 ", name = " new_name " WHERE name = " "Joe" "}")?;

See also:

@trevyn trevyn added the help wanted Extra attention is needed label Mar 9, 2021
@trevyn
Copy link
Owner Author

trevyn commented Nov 15, 2021

xref: rust-lang/rust#90473

@trevyn
Copy link
Owner Author

trevyn commented Dec 31, 2021

Implementation idea for "implicit named arguments" and expressions in the style of rust-lang/rfcs#2795: Just replace with ? and use https://docs.rs/syn/latest/syn/fn.parse_str.html

Only allow relatively straightforward replacements and SQL, and provide a fallback to positional-argument-only mode: select_positional / execute_positional? Or if it fails to validate, fall back to attempting positional.

@trevyn
Copy link
Owner Author

trevyn commented Feb 8, 2022

d21f353 allows named SQL parameters that capture from local scope; this should be enough for many use-cases.

@trevyn trevyn closed this as completed Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant