lee
leeβ€’7mo ago

Using TypeScript to Write Complex Query ...

in case it's easier, you could consider compiling the react query builder into a js function and using this helper to run the filter https://stack.convex.dev/complex-filters-in-convex
Using TypeScript to Write Complex Query Filters
There’s a new Convex helper to perform generic TypeScript filters, with the same performance as built-in Convex filters, and unlimited potential.
7 Replies
Hmza
Hmzaβ€’7mo ago
hey yeah that's a valid point. I just finished with the default filters though and its working fine right now. the one thing i really need to solve (maybe filter can help) i couldn't find any union anywhere. Does convex filters has that? Goal is to actually be able to get inside two tables and match query their documents. do you have any suggestion for that ?
lee
leeOPβ€’7mo ago
you can do two db.query calls in the same convex query
Hmza
Hmzaβ€’7mo ago
you mean inside ctx.db.query? can you context me on this Please? currently the buildFilters function i did construct the filters using FilterBuilder and Expression aswell as GenericTableInfo from convex/server and can be used like this const results = await ctx.db.query("table").order("desc").filter(filters).paginate(args.paginationOpts); you mean i can join another table here and apply same filters object to it too ? or some way else?
lee
leeOPβ€’7mo ago
i mean you can do
export const myquery = query({ // this is the convex query
args: {},
handler: async (ctx) => {
const results = await Promise.all([
// these are the multiple db queries
ctx.db.query("table").filter(filters).collect(),
ctx.db.query("othertable").filter(filters).collect(),
]);
},
});
export const myquery = query({ // this is the convex query
args: {},
handler: async (ctx) => {
const results = await Promise.all([
// these are the multiple db queries
ctx.db.query("table").filter(filters).collect(),
ctx.db.query("othertable").filter(filters).collect(),
]);
},
});
Hmza
Hmzaβ€’7mo ago
oh i know that. but i was saving myself to do a lookup function. which would be necessary with this. will see how it goes! :todayilearned: :convex: πŸ™
lee
leeOPβ€’7mo ago
reading from two tables is always going to do two lookups (even in other databases like postgres). This is just the syntax for doing it in convex
Hmza
Hmzaβ€’7mo ago
i'd not be surprised if convex turns out to be better then how we operate in regular databases. i'm not limiting myself comparing convex to other databases or this is all moot πŸ™‚ i'm a fan! and you're right ofcourse!

Did you find this page helpful?