함수: materialize()
function materialize<TContext>(query): MaterializeWrapper<GetRawResult<TContext>, TContext extends SingleResult ? true : false>;
정의 위치: packages/db/src/query/builder/functions.ts:848
includes 서브쿼리를 부모 행의 일반 값으로 구체화합니다.
- 여러 행 하위 쿼리의 경우 부모는
Array<T>스냅샷을 받습니다 (toArray()와 동일합니다). findOne()하위 쿼리의 경우 부모는 단일T | undefined값을 받습니다 — 일치하는 자식이 없으면undefined입니다.
스냅샷은 반응형으로 업데이트됩니다. 기본이 되는 자식이 변경되면 부모 행이 다시 방출됩니다.
타입 매개변수
TContext
TContext extends Context
매개변수
query
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(),
),
}))