Hey Prisma Team, Do you why does prisma rawquery n...
# orm-help
h
Hey Prisma Team, Do you why does prisma rawquery not work when I'm passing a variable. This wokrs if the variable is a number, but anything inside quotes is not working. Example from docs
Copy code
const email = '<mailto:emelie@prisma.io|emelie@prisma.io>'
const result = await prisma.$queryRaw`SELECT * FROM User WHERE email = ${email}`
This would not work as
email
is enclosed in qoutes. It would work if
const email = 2
for example DB : mySql
1
👀 1
r
Hi @Hussam Khatib 👋 You can try writing it like this
Copy code
const email = '<mailto:emelie@prisma.io|emelie@prisma.io>'
const result = await prisma.$queryRaw`SELECT * FROM "User" WHERE email = ${email}`
h
What difference does this make I am still not able to pass by variable
r
If i understand correctly, you want to pass email as a string variable using query raw
h
Yes, that example was only demonstration purpose as it was in docs. The issue variable which is passed as string does not work, this worked for when I used intergers
r
I just tested this code in my local
Copy code
const email = '<mailto:emelie@prisma.io|emelie@prisma.io>'
const result = await prisma.$queryRaw`SELECT * FROM "User" WHERE email = ${email}`
console.log(result)
The email was parsed correctly and it returned the result
Copy code
raphael@Raphaels-MBP prisma-graphql % node src/script.js
prisma:query SELECT * FROM "User" WHERE id = $1
[ { email: '<mailto:test@test.com|test@test.com>', id: 2 } ]
The difference between my query and yours is that i'm wrapping the table name with double quotes. i.e "User" but you are doing User.