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

add ability to use ':' in named args #2178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

KoNekoD
Copy link

@KoNekoD KoNekoD commented Nov 22, 2024

No description provided.

case ':':
nextRune, _ := utf8.DecodeRuneInString(l.src[l.pos:])
prevRune := rune(0)
if l.pos > 1 {
Copy link
Author

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 == '_') {
Copy link
Author

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 != ':' && ?

Comment on lines +117 to +121
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos-width])
}
l.start = l.pos
return namedArgState
Copy link
Author

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) {
Copy link
Author

@KoNekoD KoNekoD Dec 1, 2024

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

@devsalesexpress
Copy link

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

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.

2 participants