Skip to content
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

working with prisma & enums breaks formatting and/or types #197

Closed
okaisti opened this issue Jan 9, 2024 · 3 comments
Closed

working with prisma & enums breaks formatting and/or types #197

okaisti opened this issue Jan 9, 2024 · 3 comments

Comments

@okaisti
Copy link

okaisti commented Jan 9, 2024

Describe the bug

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

// This also works

interface Demo {
id: number
}

prisma.$queryRaw<Demo[]>`
  SELECT id from machine
`

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

now adding safeql to the equation, breaks, when working with enums for some reason

...
          interface Demo {
            task_definition_class_type:
              | 'BASIC'
              | 'WORK_PACKAGE'
              | 'WORK_ITEM'
              | 'ADDITIONAL'
              | 'ROADBLOCK'
              | 'TASK'
              | 'QUALITY'
              | 'LEGACY_PREREQUISITE'
              | null;
          }

          return client.$queryRaw<Demo[]>`
            SELECT
                td.class_type as task_definition_class_type
            FROM table1 ti
            LEFT JOIN table2 td ON ti.task_definition_id = td.id;
        `

results in safeql error:

Query has incorrect type annotation.
	Expected: { task_definition_class_type: "BASIC" | "WORK_PACKAGE" | "WORK_ITEM" | "TASK" | "QUALITY" | "ADDITIONAL" | "ROADBLOCK" | "LEGACY_PREREQUISITE" | null; }
	Actual: { task_definition_class_type: 'BASIC' | 'WORK_PACKAGE' | 'WORK_ITEM' | 'ADDITIONAL' | 'ROADBLOCK' | 'TASK' | 'QUALITY' | 'LEGACY_PREREQUISITE' | null; }[]eslint[@ts-safeql/check-sql](https://github.com/ts-safeql/safeql)

tried to change the order of the union keys -> didn't work either. only fix is to add a //prettier-ignore for the line, so somewhat inconvenient

this works, but again, breaks prisma syntax highlighting

          return client.$queryRaw<
            {
              task_definition_class_type:
                | 'BASIC'
                | 'WORK_PACKAGE'
                | 'WORK_ITEM'
                | 'ADDITIONAL'
                | 'ROADBLOCK'
                | 'TASK'
                | 'QUALITY'
                | 'LEGACY_PREREQUISITE'
                | null;
            }[]>`
            SELECT
                td.class_type as task_definition_class_type
            FROM table1 ti
            LEFT JOIN table2 td ON ti.task_definition_id = td.id;
        `
@karlhorky
Copy link
Collaborator

karlhorky commented Jan 9, 2024

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:

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 `):

@Newbie012
Copy link
Collaborator

I believe I fixed the issue with Query has incorrect type annotation in the pre-released version 3.0.0

You could test it by installing the pre-release version (npm i -D @ts-safeql/eslint-plugin@3.0.0.next-4).

Feedback from you would be highly appreciated 🙏

@okaisti
Copy link
Author

okaisti commented Jan 9, 2024

3.0.0-next.4 works 🙌

@okaisti okaisti closed this as completed Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants