Skip to content

Joins with a hierarchical projection (includes) #288

@samwillis

Description

@samwillis

The data shown in a user interface if often hierarchical (projects -> issues -> comments)

The joins supported by Tanstack DB are SQL like joins where the resulting rows are flat, however users will often what to project to a hierarchical structure to render in the UI.

The proposed syntax is to use subqueries in the select clause:

const projects = new Query
  .from({ project: projectsCllctn })
  .where(....)
  .select(({ project }) => ({
    project,
    issues: new Query
      .from({ issue: issuesCllctn })
      .where(({ issue }) => 
        eq(issue.projectId, project.id)
      )
      .select(({ issue }) => ({
        issue,
        comments: new Query
          .from({ comment: commentsCllctn })
          .where(({ comment }) =>
            eq(comment.issueId, issue.id)
          )
      })
   })

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions