Queries and best practices: How to query multiple tables and return object?
I have a few queries, that seems very large in terms of lines of code, and I was wondering if there is a better way to do this. This example is a get query to get multiple tables to then end up returning one object with a lot of information:
See the code example here as Discord doesn't allow longer messages:
https://stackoverflow.com/questions/78727640/queries-and-best-practices-how-to-query-multiple-tables-and-return-object-using
An example of my flow table:
So, I essentially want to get the status, priority and type of the flow returned in the same object.
I heard about the query
convex-helpers/react
but I'm not sure if that can be of any help. I was also wondering of abstracting some of the logic to other files and then importing them where I'm going to use it, is a good idea?Stack Overflow
Queries and best practices: How to query multiple tables and return...
I have a few queries, that seems very large in terms of lines of code, and I was wondering if there is a better way to do this. This example is a get query from multiple tables to then end up retur...
5 Replies
Hi @Mathias, I wrote an answer on StackOverflow; does this answer your question? The gist is "write helper functions, you don't have to write this all in one function."
Stack Overflow
Queries and best practices: How to query multiple tables and return...
I have a few queries, that seems very large in terms of lines of code, and I was wondering if there is a better way to do this. This example is a get query from multiple tables to then end up retur...
It sounds like you already know that you can do this:
I was also wondering of abstracting some of the logic to other files and then importing them where I'm going to use it, is a good idea?Yes I think this is a good idea! But are you trying to get at something else here, not just that this is a lot of lines of code but that you'd like to do something else differently here?
Hi @ballingt
Thank you for putting so much time into my questions. It definitely helped getting me back on track. Much appreciated!
I will try to write smaller helper function to sort my code more nicely, and perhaps it provides a better overview along the way.
@ballingt I see that you are mentioning
QueryCtx
. Where are those coming from? I noticed when I'm creating helper functions, that my types no longer follow along.QueryCtx is imported from "./_generated/server"