-
Notifications
You must be signed in to change notification settings - Fork 102
fix: positional params #473
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just wondering about parameter reusage?
"; | ||
test_db.execute(setup_sql).await.expect("setup sql failed"); | ||
|
||
let content = r#"select * from users where id = @one and name = :two and email = :'three';"#; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:'three'
– i want to meet the person who writes syntax like this haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha yeah I did for some time two years ago :D
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_convert_to_positional_params() { | ||
let input = "select * from users where id = @one and name = :two and email = :'three';"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about duplicate identifier names?:
select * from users
where first_name = @one
and starts_with(email, @one)
and created_at > @two;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! fixed it
pre-processes the query string to replace named params like
@name
with positional params like$1
, because only the latter is supported by the postgres parser.not super happy with the way it is used for the type checker but also did not want to put that function in another crate.
also removed a
println!
statement leftover from a previous pr of me.also fixed a bug in the lexer that tokenized a cast as a named parameter.
fixes #405, #454