MathiasM
Convex Community2y ago
6 replies
Mathias

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:

  flows: defineTable({
    title: v.string(),
    content: v.optional(v.string()),
    parentId: v.optional(v.string()),
    teamId: v.string(),
    pipelineId: v.string(),
    statusId: v.optional(v.string()),
    priorityId: v.optional(v.string()),
    typeId: v.optional(v.string()),
  })
    .index("by_team", ["teamId"])
    .index("by_parent", ["parentId"])
    .index("by_pipeline", ["pipelineId"])
    .index("by_status", ["statusId"])
    .index("by_type", ["typeId"]),


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
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...
Queries and best practices: How to query multiple tables and return...
Was this page helpful?