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

Additional Syntax Highlighting of SQL in Prisma Client raw queries

Open Jolg42 opened this issue 2 years ago • 11 comments

We recently released 4.2.0 where we now have highlighting for the following, only:

$queryRaw`` & $executeRaw``

We could support more cases like:

  • [ ] $queryRaw(), $executeRaw(), $queryRawUnsafe(), $executeRawUnsafe() using parenthesis ()
  • [ ] sql, raw (join, empty), from https://github.com/blakeembrey/sql-template-tag that can be used from The Prisma Client (see example)

Jolg42 avatar Aug 09 '22 13:08 Jolg42

Specifying the return type is currently not supported and leads to syntax highlighting getting lost.

$queryRaw<ReturnType>`my query`

P4sca1 avatar Aug 18 '22 08:08 P4sca1

@P4sca1 It works for me 🤔, could you check which version of VS Code and the Prisma VS Code extension you have? Screenshot 2022-08-19 at 14 18 11

Jolg42 avatar Aug 19 '22 12:08 Jolg42

@Jolg42 I checked again and found why it is not working for me.

// This works
prisma.$queryRaw<{ id: number }[]>`
  SELECT id from machine
`

// This does not work, because the return type declaration spans multiple lines
prisma.$queryRaw<{
  id: number
}[]>`
  SELECT id from machine
`

P4sca1 avatar Aug 19 '22 14:08 P4sca1

Indeed, I can reproduce this, thanks for the example 👍🏼

Jolg42 avatar Aug 19 '22 14:08 Jolg42

Could we get some sort of autocompletion too?

prisma.model.$executeRaw`UPDATE ${ctrl space -> shows prisma model names}`

arthurfiorette avatar Feb 08 '23 13:02 arthurfiorette

Optimally open a new issue for this @arthurfiorette - that would need to be implemente separately.

janpio avatar Feb 08 '23 14:02 janpio

Landed on this issue looking for highlighting support for code that has been abstracted out to: Prisma.sql. I really enjoyed the highlighting when I had it jammed into the $queryRaw

It seems like we have support for $queryRaw from https://github.com/prisma/language-tools/issues/74

ctsstc avatar Oct 13 '23 17:10 ctsstc

This is the meat of the PR that resolves #74: https://github.com/prisma/language-tools/pull/985/files#diff-fdb153efde4d632bf09e6ca7edb77120f2a1d8f888aae21f62d2743682c67a3e

janpio avatar Oct 13 '23 18:10 janpio

This does not work, because the return type declaration spans multiple lines

@P4sca1 The lack of syntax highlighting after multi-line generic arguments is a problem with VS Code and TextMate grammars not being able to span across multiple lines:

  • https://github.com/microsoft/vscode-textmate/issues/41

However, a workaround exists for many syntax highlighting extensions (such as SQL tagged template literals by @frigus02), to use a comment (such as /* sql */) between the generic arguments list and the template string (after the > and before the `):

  • https://github.com/frigus02/vscode-sql-tagged-template-literals/issues/20#issuecomment-1817902214

karlhorky avatar Jan 09 '24 15:01 karlhorky

Hi! I really like the syntax highlighting for $queryRaw & $queryExecute. Just wondering if there are any plans to support it too for sql & raw anytime soon?

Thank you so much

marnixhoh avatar Feb 25 '24 16:02 marnixhoh