-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 sql template literals support via plugins #12139
base: main
Are you sure you want to change the base?
Conversation
Made a quick package for our local development that incorporates those patches https://www.npmjs.com/package/@ikerin/prettier - will try to keep it up-to-date |
Seems reasonable. Is there a discussion about what this fabled better solution might entail though? There's obviously a desire for more and different template literal decorators, so much so that Microsoft have themselves developed an extension mechanism for it. Prettier already has this wonderful plugin system, it doesn't look like too much of a stretch to add some more configs to it, and maybe even implement all the other template literal embeds with it? I'm happy to try and delve into the innards of prettier if you guys are too busy with other stuff, but I'd really appreciate some direction. I know nobody wants a huge PR bomb dropped in their lap :) |
It's quite disappointing that the As it stands, the current API is almost useless, because of the indirection it creates: I have to create a plugin for the language the embedding will be insert to, instead of a plugin for the embedded language itself. |
Also |
For anyone finding this and looking for another alternative for formatting SQL in embedded Prettier can be used with the combination of the |
Back to this current PR, @fisker @sosukesuzuki @thorn0 what do you and Prettier team think of reconsidering this PR? It may not be the most clean, extensible approach wished for by @ikatyang in #4424, but maybe it would be nice for at least SQL to become a first-class citizen like GraphQL and CSS. Especially now that the industry is getting a lot of movement around
If SQL tagged template literal support was first-class in Prettier core, then plugins like |
It would be highly valuable to have some formatting being auto applied to the sql inside html template strings, relying on my devs to keep it clean isn't a guaranteed way to do it. |
Personally, I don't want to accept SQL specific code. We should consider designing a general mechanism for using plugins with embedded formatting. |
Ok, thanks for the answer. What makes SQL different than eg. GraphQL for you? Or do you mean that first-class Prettier support of GraphQL was also a mistake? |
GraphQL was already supported when I became a maintainer. |
Ok, so if I'm understanding, the first-class support using the current system is the part that is unwanted (maybe the code is hard to maintain or has other problems) and should be rebuilt, meaning that any out-of-the-box support like GraphQL and CSS support will also be moved to the new system. Would be great for users to get SQL support before this rewrite, but I understand that your position is that no new embedded languages should be added to the old, undesirable system. |
Description
Add support for prettifying sql template literals.
This does not add the support itself, just the ability to do so by plugins, if they provide the "sql" parser/printer. Does not change any behaviour if no plugins like that are present.
I'm developing a Postgres sql typescript type generator - potygen. As part of that effort I've ended up with a pretty decent pure JS sql parser and figured - lets do a sql prettier plugin. And that turned out working great too.
To my horror though 😱 all of our
sql
template literals in our service didn't magically become pretty! Reading the issues and source it quickly became obvious that there are only several blessed tags that are processed, and my newly minted prettifier would be delegated to the cold wintery post of just dealing with raw sql files. That's great and all, but I was craving for more!I'm also not the only one figuring "raw sql is better than ORM", and indeed I've found a lot of like minded folk along the way - squid, ts-mysql-analyzer, pgtyped and I'm sure many others, so the need and desire for sql template literals is here, we just need prettier to allow us to plug that in.
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨