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

Ability to use ":" instead of "@" in named args #2177

Open
KoNekoD opened this issue Nov 22, 2024 · 9 comments
Open

Ability to use ":" instead of "@" in named args #2177

KoNekoD opened this issue Nov 22, 2024 · 9 comments

Comments

@KoNekoD
Copy link

KoNekoD commented Nov 22, 2024

Add ability to use ":" instead of "@" in named args

Sql linter in golang like this

@KoNekoD
Copy link
Author

KoNekoD commented Nov 22, 2024

@KoNekoD
Copy link
Author

KoNekoD commented Nov 22, 2024

PR #2178

Before(bad)

image

image

After (good)

image

@jackc
Copy link
Owner

jackc commented Nov 29, 2024

: is tricky because it is also used for type conversion, e.g. select somecol::text. As far as I can tell, #2178 would fail when :: is encountered.

But even if the parser was fixed I'd rather there only be way to denote a named argument.

However, pgx.[Strict]NamedArgs does not require any internal pgx functionality. It simply implements the pgx.QueryRewriter interface. If you really need to use :, you can copy NamedArgs into your project and change it there.

@KoNekoD
Copy link
Author

KoNekoD commented Dec 1, 2024

@jackc I see your point, I'll make the edits according to your concerns.

@KoNekoD
Copy link
Author

KoNekoD commented Dec 1, 2024

@jackc Done; Commit 2aa476d

This implementation turns out to be independent and takes into account cases of type casts

@jackc
Copy link
Owner

jackc commented Dec 5, 2024

The code looks more solid now.

But as I said above, I want to keep the simplicity of only having a single delimiter for named arguments.

I think this support for : should be pulled out into your own library or application.

@KoNekoD
Copy link
Author

KoNekoD commented Dec 7, 2024

@jackc Are you sure that library users will be comfortable being forced to adjust to your understanding of good? There seem to be some people who don't like it when their IDE frowns on '@' substitutions. Maybe we should pay attention to the convenience for the end user of the library?

@Nerobrain
Copy link

Nerobrain commented Dec 9, 2024

@KoNekoD Are you sure that library users will be comfortable being forced to adjust to your understanding of good? There seem to be some people who know the difference between errors and linter faults. Maybe we should pay attention to the workload for the author of the library?

@devsalesexpress
Copy link

devsalesexpress commented Dec 26, 2024

:é complicado porque também é usado para conversão de tipo, por exemplo select somecol::text. Até onde eu sei, #2178 falharia quando ::fosse encontrado.

Mas mesmo que o analisador fosse corrigido, eu preferiria que houvesse apenas uma maneira de denotar um argumento nomeado.

No entanto, pgx.[Strict]NamedArgsnão requer nenhuma funcionalidade interna do pgx. Ele simplesmente implementa a pgx.QueryRewriterinterface. Se você realmente precisa usar :, você pode copiar NamedArgspara o seu projeto e alterá-lo lá.

Just check if the successor (the next character) is also a colon ':' if it is then it is a parameter so do not replace the value.

Example: select id::integer as id from person where id = :id

In id::integer contains '::' when it finds the first ':' you check if the next character is also a ':' so it will be a cast and not a parameter.

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

No branches or pull requests

4 participants