function materialize<TContext>(query): MaterializeWrapper<GetRawResult<TContext>, TContext extends SingleResult ? true : false>;function materialize<TContext>(query): MaterializeWrapper<GetRawResult<TContext>, TContext extends SingleResult ? true : false>;Defined in: packages/db/src/query/builder/functions.ts:848
Materialize an includes subquery into a plain value on the parent row.
The snapshot updates reactively: parent rows re-emit when the underlying children change.
TContext extends Context
QueryBuilder<TContext>
MaterializeWrapper<GetRawResult<TContext>, TContext extends SingleResult ? true : false>
// Multi-row: produces Array<Issue> on each project
select(({ p }) => ({
...p,
issues: materialize(
q.from({ i: issues }).where(({ i }) => eq(i.projectId, p.id)),
),
}))
// Singleton: produces Author | undefined on each post
select(({ p }) => ({
...p,
author: materialize(
q.from({ a: authors }).where(({ a }) => eq(a.id, p.authorId)).findOne(),
),
}))// Multi-row: produces Array<Issue> on each project
select(({ p }) => ({
...p,
issues: materialize(
q.from({ i: issues }).where(({ i }) => eq(i.projectId, p.id)),
),
}))
// Singleton: produces Author | undefined on each post
select(({ p }) => ({
...p,
author: materialize(
q.from({ a: authors }).where(({ a }) => eq(a.id, p.authorId)).findOne(),
),
}))