How to convert filters (e.g. eq(), ne(), lte(), like()) into SQL string, for use in sql.raw()
I'm trying to use
LEFT JOIN LATERAL
, but I have a lot of filters already created with drizzle. I would like to use them in my SQL:
3 Replies
This gets me halfway there: https://orm.drizzle.team/docs/sql#convert-sql-to-string-and-params
But the problem is the params I passed into the filters (e.g. eq(user.id, userId)) is not added to the string.
Drizzle ORM - Magic sql`` operator
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Did you try with just sql (no raw).
In the template string you can use all drizzle expressions (and inject sql.raw too if needed but beware, this is an unsafe injection, prone to sql injection)
I tried sql too, but it errors with
error: syntax error at or near ")"
ahh i know why that happens. Basically, the filter queryParams.startTime is sometimes undefined: it's number | undefined
. I just need to use sql
a bit better