mono2712
mono2712
DTDrizzle Team
Created by mono2712 on 12/12/2023 in #help
Add the appropriate Drizzle types to a helper function?
I'm trying to build "dynamic" relational queries with the buildAndConditions helper function. Here's a TS playground: http://tinyurl.com/bdf9r4mn
1 replies
DTDrizzle Team
Created by mono2712 on 11/21/2023 in #help
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.
8 replies