DB Docs
API Reference
- Core API Reference
- Collection
- createCollection
- liveQueryCollectionOptions
- createLiveQueryCollection
- createOptimisticAction
- createTransaction
- Electric DB Collection
- electricCollectionOptions
- Query DB Collection
- queryCollectionOptions
- RxDB DB Collection
- rxdbCollectionOptions
- PowerSync Collection
- powerSyncCollectionOptions
- createIndexedDB
- indexedDBCollectionOptions
- React Hooks
- useLiveQuery
AI/LLM: This documentation page is available in plain markdown format at/db/latest/docs/reference/functions/materialize.md
materialize
ts
function materialize<TContext>(query): MaterializeWrapper<GetInlineResult<TContext>, TContext extends SingleResult ? true : false>;Defined in: packages/db/src/query/builder/functions.ts:882
Materialize an includes subquery into a plain value on the parent row.
- For multi-row subqueries, the parent receives an Array<T> snapshot (equivalent to toArray()).
- For findOne() subqueries, the parent receives a single T | undefined value — undefined when no child matches.
The snapshot updates reactively: parent rows re-emit when the underlying children change.
Type Parameters#
TContext#
TContext extends Context
Parameters#
query#
QueryBuilder<TContext>
Returns#
MaterializeWrapper<GetInlineResult<TContext>, TContext extends SingleResult ? true : false>
Example#
ts
// 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(),
),
}))