Dynamic Drizzle Relational Queries

Hi everybody, hope all is well. I was wondering if there is a way to build dynamic queries when using drizzle (relational) queries.

I read the section on dynamic query building but it doesn't cover relational queries.

I'm building a rest API and I want users to be able to pass filters via query params.

I have a tours table, tours can have many images as well as many start dates.

Is there a way of doing something like this? And make it flexible enough so that the user can filter based on various operations for different columns (ie: equal, lt, lte, gt, gte, like, etc...).

// pseudo code

db.query.tours.findMany({
  where: <dynamically generated where filters for tour>,
  with: { images: {
    where: <dynamically generated where filters for images>
  }, startDates: {
    where: <dynamically generated where filters for start dates>
  } },
})


How would you solve this?

Thanks in advance, this would help me a lot.
Was this page helpful?