-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Way to convert QueryAs to string #1771
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
Comments
The bindings are not formatted into the string, the string you give it is the one that's sent to the database and the bindings are sent alongside in a binary encoding. |
That makes sense, thank you. My thought is it would be best in a test assertion to assert against a string which includes bound variables interpolated, so it's easy to visually inspect where they were bound, given human error in writing queries with many variables. How would you suggest going about this? |
#875 is intended to make it harder to mess up with bindings. |
That looks great! Approximately how far away is that, because I'm hoping to get this testing in a nice place asap? If it's on the order of months, which in the open source world could mean next year, possibly there's a quicker short term solution? |
I don't have an exact timeline on it, nor do I have a good solution here right now. What I typically do for queries long enough that I'm worried about mixing up bind parameters, is leave a comment at the top of the query noting what is what so it's easier to keep track. This really only works for Postgres and SQLite though, which have numbered/named bind parameters: sqlx::query!(
// $1: foo_id
// $2: bar_id
// $3: baz_id
r#"
select * from foo
inner join bar on foo.bar_id = bar.id
inner join baz on bar.baz_id = baz.id
where foo.id = $1 and bar.id = $2 and baz.id = $3
"#,
foo_id,
bar_id,
baz_id
) |
@abonander |
I'd like a way to convert QueryAs to string in order to assert against the raw bound sql string, however it looks like the function that produces a string is not
pub
sqlx/sqlx-core/src/query_as.rs
Line 30 in d3093d0
The text was updated successfully, but these errors were encountered: