MCPcopy Index your code
hub / github.com/TanStack/db / buildNestedAggregateToArrayQuery

Function buildNestedAggregateToArrayQuery

packages/db/tests/query/includes.test.ts:4036–4056  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4034
4035 describe(`nested aggregate: count comments per issue (as toArray)`, () => {
4036 function buildNestedAggregateToArrayQuery() {
4037 return createLiveQueryCollection((q) =>
4038 q.from({ p: projects }).select(({ p }) => ({
4039 id: p.id,
4040 name: p.name,
4041 issues: q
4042 .from({ i: issues })
4043 .where(({ i }) => eq(i.projectId, p.id))
4044 .select(({ i }) => ({
4045 id: i.id,
4046 title: i.title,
4047 commentCount: toArray(
4048 q
4049 .from({ c: comments })
4050 .where(({ c }) => eq(c.issueId, i.id))
4051 .select(({ c }) => ({ total: count(c.id) })),
4052 ),
4053 })),
4054 })),
4055 )
4056 }
4057
4058 it(`each issue gets its own comment count as an array`, async () => {
4059 const collection = buildNestedAggregateToArrayQuery()

Callers 1

includes.test.tsFile · 0.85

Calls 7

toArrayFunction · 0.85
selectMethod · 0.80
fromMethod · 0.80
whereMethod · 0.80
eqFunction · 0.70
countFunction · 0.50

Tested by

no test coverage detected