-
Notifications
You must be signed in to change notification settings - Fork 854
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
add ability to use ':' in named args #2178
base: master
Are you sure you want to change the base?
Conversation
case ':': | ||
nextRune, _ := utf8.DecodeRuneInString(l.src[l.pos:]) | ||
prevRune := rune(0) | ||
if l.pos > 1 { |
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.
I added this check to avoid panic when : is at the beginning of a line.
if l.pos > 1 { | ||
prevRune, _ = utf8.DecodeRuneInString(l.src[l.pos-2:]) | ||
} | ||
if nextRune != ':' && prevRune != ':' && (isLetter(nextRune) || nextRune == '_') { |
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.
It seems to me that we can omit the first check nextRune != ':' as there will be a more specific check next, but in addition I would like to say that this check is much easier than the next ones, and will cut off cast types a little faster.... But type casts are not done so often to leave this prevenient check.
What do you think, should I remove nextRune != ':' &&
?
if l.pos-l.start > 0 { | ||
l.parts = append(l.parts, l.src[l.start:l.pos-width]) | ||
} | ||
l.start = l.pos | ||
return namedArgState |
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.
Copy from '@' case
@@ -160,3 +160,155 @@ func TestStrictNamedArgsRewriteQuery(t *testing.T) { | |||
} | |||
} | |||
} | |||
|
|||
func TestNamedArgsRewriteQuery2(t *testing.T) { |
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.
I also added a tests that should confirm the clarity of my implementation
The implementation of KoNekoD makes perfect sense, I also have this need and I made the change in my project and it worked perfectly as expected, because I have queries that run on Postgres, Oracle and MySql and by default we use the named parameter with ':', for example :id Ability to use ":" instead of "@" in named arg |
No description provided.