nene / sql-parser-cst

Parses SQL into Concrete Syntax Tree (CST)
GNU General Public License v2.0
115 stars 7 forks source link

Feature request: Parse JSON_BUILD_OBJECT() with one key-value pair per line #72

Closed marnixhoh closed 2 months ago

marnixhoh commented 2 months ago

Hi!

First of all, thank you so much for your work on creating this new improved sql parser & the prettier sql formatter! I can't wait for Postgres to be fully supported soon 🚀

Most sql formatters format JSON_BUILD_OBJECT() just as any other function. Meaning that with a good number of parameters it will be formatted as:

SELECT JSON_BUILD_OBJECT(
  'key1', 
  'val1',
  'key2, 
  'val2',
  ...
)

However, it is commonly formatted such that each key-value pair is on the same line. This make it much more readable and is also the way json objects are normally displayed:

SELECT JSON_BUILD_OBJECT(
  'key1', 'val1',
  'key2, 'val2',
  ...
)

It would be amazing if the formatting of the JSON_BUILD_OBJECT() function could be implemented this way.

Thank you so much for considering this. :)

nene commented 2 months ago

Thanks for a suggestion.

While I think it would be nice to format the contents of this function like this, I have to reject this feature for now. It's way too specific case for a very specific function. I instead would like to concentrate on solving more general formatting issues first before tackling such cases.

Also, I think there might be a more generic feature hidden here. It's not the only case where one would like to format a list of items in some sort of grid-like way. Like when representing a 3D matrix. But that too is a task for future.

Finally, this issue doesn't really belong to this repository - this one is for the parser, but the issue is about formatting.