Difference Between sql-formatter and prettier-plugin-sql-cst #611
Replies: 3 comments
-
Mostly, but the implementation approach it takes is a much more labor-intensive one. Importantly, it needs a full SQL parser implementation of each dialect that it supports. And accordingly it only works when it's able to fully parse its input SQL. The upside of this is that the formatter can fully understand the language it's formatting and take advantage of it. The sql-formatter library has a more heuristic approach. It essentially looks for some familiar tokens in the input text and tries to reorganize the whitespace between them. But it has a fairly limited understanding of the actual language structure, which leads to various bugs like not being able to distinguish when
That's what I've actually been doing. Though at the moment I don't really have much time to develop the new library, so I've pretty much limited myself to responding to the bug reports in this repository. These two libraries will probably both go on existing for a long time though, because implementing support in the new lib for all the dialects that sql-formatter supports is such a grand undertaking. |
Beta Was this translation helpful? Give feedback.
-
What about prettier-plugin-sql? |
Beta Was this translation helpful? Give feedback.
-
This library is just a lightweight wrapper around sql-formatter. It also has an option of using |
Beta Was this translation helpful? Give feedback.
-
I know @nene has mentioned on several occasions that there are some fundamental problems with sql-formatter. I wanted to create a post that describes the main problems that will be addressed in prettier-plugin-sql-cst.
Some of the initial questions I have:
Beta Was this translation helpful? Give feedback.
All reactions