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

$queryRaw doesn't create prepared statements correctly #136

Open
Noor0 opened this issue Mar 5, 2024 · 0 comments
Open

$queryRaw doesn't create prepared statements correctly #136

Noor0 opened this issue Mar 5, 2024 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@Noor0
Copy link

Noor0 commented Mar 5, 2024

function getUsers(ids: number[], filter?: string) {
  const filterStatement = `%${filter}%`
  return $queryRaw`SELECT * FROM users WHERE id IN (${Prisma.join([ids])}) ${filter ? Prisma.sql`OR email LIKE ${filterStatement}` : Prisma.empty}`
}

The query above works fine outside of tests but, in a test with jest-prisma It creates a bad prepared-statement that looks like this in the logs

postgres-1  | 2024-03-05 08:10:26.809 UTC [348] ERROR:  syntax error at or near "$2" at character 45
postgres-1  | 2024-03-05 08:10:26.809 UTC [348] STATEMENT:
postgres-1  | 	      SELECT * FROM users WHERE id IN ($1) $2
postgres-1  |

and results in a PrismaClient error

PrismaClientKnownRequestError:
    Invalid `prisma.$queryRaw()` invocation:


    Raw query failed. Code: `42601`. Message: `ERROR: syntax error at or near "$2"`
@Quramy Quramy added the help wanted Extra attention is needed label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants