Optional filtering
I'm trying to figure out the right pattern to reproduce an SQL query where the user can optionally filter based on a column value. For example, assuming a
chunks
table with a documentId
column, you could write the query
The corresponding pattern in Drizzle is not obvious because neither isNull
or and/or
can accept JS values as options, only SQL columns. So the following pattern doesn't work:
Does anyone have a good way to do this?2 Replies
Dug through some earlier threads, apparently conditionally constructing the
where
array is the way to go! so in this case:
then just select()...where(...where)
you could probably do this as well
or something similar
might need
sql.raw()
idk
but if that works then cool
you might need to transform it via json
but yeah
probably less ideal