How to query todos from multiple lists/all lists
Using drizzle ORM and SvelteKit, how do I select todos from multiple lists or all lists? Right now this query function only allows me to query 1 list.
I'm still an amateur trying to figure out SvelteKit and Drizzle. Appreciate the help!
5 Replies
In the case If you're looking for all todos by owner, just drop the second where condiion that filters on the list ID
If you have an array of list IDs you want to include, use
inArray(toDo.list, arrayOfIds)
Keep in mind that if you're getting that list of IDs from the database, it may be more efficient to combine those operations into one query, depending on the situationThank you @Luxaritas ! Is there a way to just use 1 function to query multiple lists/ all lists from 1 owner? What I mean by this is if it's possible to make the second parameter "list" optional. Appreciate the help :))
Sure.
and
has a handy shortcut where it will ignore any parameters that are undefined
So you could do something like and(eq(toDo.ownerId, ownerId), listIds ? inArray(toDo.list, listIds) : undefined)
This is amazing. Thank you so much @Luxaritas !
yw!