vulkd / vscode-inline-sql-formatter

"Beautify" SQL in any file 💅
3 stars 1 forks source link

Enhancement for SQL bind-variables #1

Open zipelkopf opened 3 years ago

zipelkopf commented 3 years ago

Hi, thanks for your extension :-)

I'm using inline SQL with other coding languages like PHP and a common implementation is using the so called bind-variables that are escaped and passed into the SQL as parameters. A special character is usually defined to identify the inline parameter within the SQL, like : but anthing else can be defined.

This is a SQL example before formatting, please note the :myParam

SELECT
    NULL
FROM
    t_sample
WHERE
    smp_id = :myParam

The problem is that any symbol near the parameter gets moved after formatting, changing from :myParam into : myParam. See below

SELECT
    NULL
FROM
    t_sample
WHERE
    smp_id = : myParam

Would you consider enhancing your plugin with the following ideas?

  1. Add an optional parameter in the plugin's settings so to choose the symbol for bind-variables. Then alter the formatting accordingly by taking into accound the chosen symbol.
  2. Otherwise, if the above is too much, just fix the formatting. Perhaps symbols that are not reserved in the SQL context, like :, should not be moved of position.

Thanks a mill!

P.S. Some others formatting extensions do not have this problem, but they do not nicelly format like yours, so I hope for your help here :-)

zipelkopf commented 3 years ago

FYI, the SQL Formatter Mod does the job. I think it's based on sql-formatter-plus rather than sql-formater.

Cheers