Hi! Any tips how to separate raw query to a separa...
# prisma-client
t
Hi! Any tips how to separate raw query to a separate function and populate it with parameters? Eg. queryCollection.ts:
export function getEmailQuery(email: string): string {
return `SELECT * FROM User WHERE email = ${email}`; }
If I call as following:
await this.prisma.$queryRaw` ${getEmailQuery("email@email.com")}`;
Prisma gives error :
Raw query failed. Code:
42601
. Message:
db error: ERROR: syntax error at or near "$1"
a
I believe you could use queryRawUnsafe in this instance.
t
Seems to work! So basically I'll just need to safe check the parameters, which are passed to the function, which returns the query string
a
Yep! Prisma's warning you that it's passing your parameters on as a string, so you're responsible for sanitizing/ensuring you don't need to sanitize