Hi all, I am having an issue with `prisma.$queryRa...
# orm-help
r
Hi all, I am having an issue with
prisma.$queryRaw
and using sql
ORDER BY
. I am passing in the order by and direction values as parameters, however the query is not working e.g.
Copy code
ORDER BY ${orderBy} ${direction}

should become

ORDER BY name ASC
Don't suppose anyone has any ideas? Before I've used pg promise
:raw
but not sure how to do this the 'prisma way'. Apologies if anything isn't clear.
r
@Reuben Porter 👋 You cannot use
$queryRaw
for passing in columns and keywords. You need to use
$queryRawUnsafe
for this and sanitise your inputs.
r
Thanks for the response. ahh that's such a shame, was hoping I didn't have to do my own sanitisation!
So there is no other safe way of having a dynamic order by?
@Ryan
r
There is but you’ll need to have a lot of conditions: https://github.com/blakeembrey/sql-template-tag/issues/17
Have a look at the above thread as Prisma uses the same API for raw queries under the hood.
r
Ok I will take a read thanks
👍 1