language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

SQL Formatting for queryRaw

Open leo-petrucci opened this issue 5 years ago • 4 comments

Problem

My API, as many other I assume, has a couple of complex queries that can't be achieved with Prisma, because of this I'm kind of forced to use queryRaw and write it in plain ole SQL. The problem with this is that the SQL is almost always a mess as there's no way for it to be automatically formatted.

VsCode has a bunch of extensions that allow you to format strings written after an sql tag like this:

sql`<code query here>`

but they don't work with Prisma.

Suggested solution

Ideally a VScode plugin that automatically formats anything written after queryRaw would be perfect. Maybe forking one of the existing plugins would work?

Alternatives

I've used some online formatters but they really really suck 😂

leo-petrucci avatar Jan 29 '21 09:01 leo-petrucci

I do the formatting in PopSQL at the moment. It works flawlessly, but copy-pasting SQL from VSCode to another software and back only for formatting feels dumb.

The VSCode formatter/highlighter extension seem to work when you wrap the SQL in Prisma.sql, but that can't be used when you need to dynamically pass in table or column names. Passing in column names is pretty common I suppose for sorting purposes for example so this pretty much renders Prisma.sql useless for this use case.

slinden2 avatar Feb 15 '21 15:02 slinden2

Closing as a duplicate of https://github.com/prisma/language-tools/issues/74

Jolg42 avatar Nov 16 '21 16:11 Jolg42

#74 was closed after syntax highlighting was implemented, but there is still no auto-format available that I know if. Is it available somehow? I'm using VSCode and Prettier by default.

phoenixeliot avatar Sep 21 '22 19:09 phoenixeliot

No, that is fair - we implemented highlighting, but not formatting. I'll reopen this issue so we can track that.

janpio avatar Sep 22 '22 11:09 janpio