Closed wmertens closed 2 years ago
Don't see why not.
It should be a simple addition to add another condition to match a string.
Don't have time to add this right now (working on some of my other projects), but will certainly add it soonish. If you want to give it a go I can help you out.
Actually why do you need this for? Potygen has 3 main things it kinda does for you, and not sure what effect are you after exactly?
Now 2 is a typescript feature and I can't really change how it works - only string template literals.
3 kinda wouldn't work in your proposal as the string template literal does more things for you than just hold the string of the SQL - it converts the $param into positional params (?
) that Postgres accepts.
1 though - I think I can do a prettier fix to auto format strings with an sql comment, but that would be pretty much it.
I'm the author of https://github.com/StratoKit/strato-db and we use it internally a lot, and sometimes I need to run real SQL instead of calling the wrapper methods. In those rare cases, I don't use the sql
template function even though I have one, because I rarely interpolate and I feel guilty about the tiny overhead :sweat_smile:.
Add to that that currently Prettier doesn't support custom template functions and I was thinking that a comment would be easier. SQLite syntax is very similar to PostGreSQL so that's how I ended up here.
So I wouldn't be using the typescript features at all, unless I could make them work on strato-db, but even they would be of limited use.
Ok so - prettier.
Have in mind that for prettier to work with potygen, you need to use a patched version of it (a few lines changed, but still), until they add official support for it, and we’re only talking about template literals, things like comment hints are something I doubt they’ll add anytime soon.
If you manage to convince them about it here - https://github.com/prettier/prettier/pull/12139 I’ll be more than happy to extend my plugin to support it.
In fact the potygen prettier plugin works by specifying “sql” as a language, as long as prettier recognizes it somewhere it would work. Its just they don’t expose “sql” as an embedded language, and I had to patch it.
On the upside you can write sql in .sql files and prettier will pick them up and format them with this plugin.
Ok fair enough, I'lll close this issue. Hopefully template function names will be configurable in Prettier soon, but it doesn't seem likely.
Would it be possible to make a comment like
/*sql*/
treat the next string literal as SQL to parse?like in
or