ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Teamโ€ข3y agoโ€ข
7 replies
eduardoaosorio

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>
  } },
})
// 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.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

dynamic relational queries column returns
Drizzle TeamDTDrizzle Team / help
3y ago
Conditional Relational Queries
Drizzle TeamDTDrizzle Team / help
3y ago
Relational queries (PlanetScale)
Drizzle TeamDTDrizzle Team / help
3y ago
Help with relational queries
Drizzle TeamDTDrizzle Team / help
9mo ago