본문으로 건너뛰기

타입 별칭: MergeContextForJoinCallback<TContext, TNewSchema>

type MergeContextForJoinCallback<TContext, TNewSchema> = object & PreserveHasResultFlag<TContext["hasResult"]> & PreserveUnionFromFlag<TContext["hasUnionFrom"]> & PreserveFromSourceNames<TContext["fromSourceNames"]>;

정의 위치: packages/db/src/query/builder/types.ts:1272

MergeContextForJoinCallback - 조인 조건 콜백을 위한 특수 컨텍스트

이 타입은 조인 작업의 onCallback 매개변수를 위한 컨텍스트를 특별히 생성합니다. MergeContextWithJoinType과의 주요 차이점은 여기에는 선택 사항 여부가 적용되지 않는다는 점입니다.

선택 사항 여부를 적용하지 않는 이유 SQL에서는 선택 사항 여부가 결정되기 전에 조인 조건이 평가됩니다. 조인 조건 자체에서는 두 테이블을 모두 사용 가능한 상태(선택 사항 아님)로 처리해야 합니다. 선택 사항 여부는 조인 로직이 실행된 후 결과에만 적용됩니다.

예시:

.from({ users })
.leftJoin({ orders }, ({ users, orders }) => {
// users is NOT optional here - we can access users.id directly
// orders is NOT optional here - we can access orders.userId directly
return eq(users.id, orders.userId)
})
.where(({ orders }) => {
// NOW orders is optional because it's after the LEFT JOIN
return orders?.status === 'pending'
})

단순 교집합(&)은 선택 사항 여부 변환 없이 스키마를 병합합니다.

타입 선언

baseSchema

baseSchema: TContext["baseSchema"];

fromSourceName

fromSourceName: TContext["fromSourceName"];

hasJoins

hasJoins: true;

joinTypes

joinTypes: TContext["joinTypes"] extends Record<string, any> ? TContext["joinTypes"] : object;

refsSchema

refsSchema: RefsSchemaForContext<TContext> & TNewSchema;

result

result: TContext["result"];

schema

schema: TContext["schema"] & TNewSchema;

타입 매개변수

TContext

TContext extends Context

TNewSchema

TNewSchema extends ContextSchema