본문으로 건너뛰기

함수: queryCollectionOptions()

호출 시그니처

function queryCollectionOptions<T, TQueryFn, TError, TQueryKey, TKey, TQueryData>(config): CollectionConfig<InferSchemaOutput<T>, TKey, T, QueryCollectionUtils<InferSchemaOutput<T>, TKey, InferSchemaInput<T>, TError>> & object;

정의 위치: packages/query-db-collection/src/query.ts:535

표준 컬렉션과 함께 사용할 쿼리 컬렉션 옵션을 생성합니다. 자동 동기화를 위해 TanStack Query를 TanStack DB와 통합합니다.

다음 우선순위에 따라 자동 타입 추론을 지원합니다.

  1. 스키마 추론(최우선)
  2. QueryFn 반환 타입 추론(두 번째 우선순위)

타입 매개변수

T

T 확장 StandardSchemaV1&lt;unknown, unknown>

스키마가 제공된 경우 스키마의 타입이며, 그렇지 않으면 queryFn이 반환하는 값의 타입입니다.

TQueryFn

TQueryFn 확장 (context) => any

TError

TError = unknown

쿼리 중 발생할 수 있는 오류의 타입입니다.

TQueryKey

TQueryKey 확장 readonly unknown[] = readonly unknown[]

쿼리 키의 타입입니다.

TKey

TKey 확장 string | number = string | number

항목 키의 타입입니다.

TQueryData

TQueryData = Awaited&lt;ReturnType&lt;TQueryFn>>

매개변수

config

QueryCollectionConfig&lt;InferSchemaOutput&lt;T>, TQueryFn, TError, TQueryKey, TKey, T, Awaited&lt;ReturnType&lt;TQueryFn>>> & object

Query 컬렉션의 구성 옵션입니다.

반환값

CollectionConfig&lt;InferSchemaOutput&lt;T>, TKey, T, QueryCollectionUtils&lt;InferSchemaOutput&lt;T>, TKey, InferSchemaInput&lt;T>, TError>> & object

직접 쓰기 및 수동 작업을 위한 유틸리티가 포함된 컬렉션 옵션입니다.

예시

// Type inferred from queryFn return type (NEW!)
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => {
const response = await fetch('/api/todos')
return response.json() as Todo[] // Type automatically inferred!
},
queryClient,
getKey: (item) => item.id, // item is typed as Todo
})
)
// Explicit type
const todosCollection = createCollection<Todo>(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
queryClient,
getKey: (item) => item.id,
})
)
// Schema inference
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
queryClient,
schema: todoSchema, // Type inferred from schema
getKey: (item) => item.id,
})
)
// With persistence handlers
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: fetchTodos,
queryClient,
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
await api.createTodos(transaction.mutations.map(m => m.modified))
},
onUpdate: async ({ transaction }) => {
await api.updateTodos(transaction.mutations)
},
onDelete: async ({ transaction }) => {
await api.deleteTodos(transaction.mutations.map(m => m.key))
}
})
)
// The select option extracts the items array from a response with metadata
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
select: (data) => data.items, // Extract the array of items
queryClient,
schema: todoSchema,
getKey: (item) => item.id,
})
)

호출 시그니처

function queryCollectionOptions<T, TQueryFn, TError, TQueryKey, TKey, TQueryData>(config): CollectionConfig<T, TKey, never, QueryCollectionUtils<T, TKey, T, TError>> & object;

정의 위치: packages/query-db-collection/src/query.ts:570

표준 컬렉션과 함께 사용할 쿼리 컬렉션 옵션을 생성합니다. 자동 동기화를 위해 TanStack Query를 TanStack DB와 통합합니다.

다음 우선순위에 따라 자동 타입 추론을 지원합니다.

  1. 스키마 추론(최우선)
  2. QueryFn 반환 타입 추론(두 번째 우선순위)

타입 매개변수

T

T 확장 object

스키마가 제공된 경우 스키마의 타입이며, 그렇지 않으면 queryFn이 반환하는 값의 타입입니다.

TQueryFn

TQueryFn 확장 (context) => any = (context) => any

TError

TError = unknown

쿼리 중 발생할 수 있는 오류의 타입입니다.

TQueryKey

TQueryKey 확장 readonly unknown[] = readonly unknown[]

쿼리 키의 타입입니다.

TKey

TKey 확장 string | number = string | number

항목 키의 타입입니다.

TQueryData

TQueryData = Awaited&lt;ReturnType&lt;TQueryFn>>

매개변수

config

QueryCollectionConfig&lt;T, TQueryFn, TError, TQueryKey, TKey, never, TQueryData> & object

Query 컬렉션의 구성 옵션입니다.

반환값

CollectionConfig&lt;T, TKey, never, QueryCollectionUtils&lt;T, TKey, T, TError>> & object

직접 쓰기 및 수동 작업을 위한 유틸리티가 포함된 컬렉션 옵션입니다.

예시

// Type inferred from queryFn return type (NEW!)
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => {
const response = await fetch('/api/todos')
return response.json() as Todo[] // Type automatically inferred!
},
queryClient,
getKey: (item) => item.id, // item is typed as Todo
})
)
// Explicit type
const todosCollection = createCollection<Todo>(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
queryClient,
getKey: (item) => item.id,
})
)
// Schema inference
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
queryClient,
schema: todoSchema, // Type inferred from schema
getKey: (item) => item.id,
})
)
// With persistence handlers
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: fetchTodos,
queryClient,
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
await api.createTodos(transaction.mutations.map(m => m.modified))
},
onUpdate: async ({ transaction }) => {
await api.updateTodos(transaction.mutations)
},
onDelete: async ({ transaction }) => {
await api.deleteTodos(transaction.mutations.map(m => m.key))
}
})
)
// The select option extracts the items array from a response with metadata
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
select: (data) => data.items, // Extract the array of items
queryClient,
schema: todoSchema,
getKey: (item) => item.id,
})
)

호출 시그니처

function queryCollectionOptions<T, TError, TQueryKey, TKey>(config): CollectionConfig<InferSchemaOutput<T>, TKey, T, QueryCollectionUtils<InferSchemaOutput<T>, TKey, InferSchemaInput<T>, TError>> & object;

정의 위치: packages/query-db-collection/src/query.ts:603

표준 컬렉션과 함께 사용할 쿼리 컬렉션 옵션을 생성합니다. 자동 동기화를 위해 TanStack Query를 TanStack DB와 통합합니다.

다음 우선순위에 따라 자동 타입 추론을 지원합니다.

  1. 스키마 추론(최우선)
  2. QueryFn 반환 타입 추론(두 번째 우선순위)

타입 매개변수

T

T 확장 StandardSchemaV1&lt;unknown, unknown>

스키마가 제공된 경우 스키마의 타입이며, 그렇지 않으면 queryFn이 반환하는 값의 타입입니다.

TError

TError = unknown

쿼리 중 발생할 수 있는 오류의 타입입니다.

TQueryKey

TQueryKey 확장 readonly unknown[] = readonly unknown[]

쿼리 키의 타입입니다.

TKey

TKey 확장 string | number = string | number

항목 키의 타입입니다.

매개변수

config

QueryCollectionConfig&lt;InferSchemaOutput&lt;T>, (context) => InferSchemaOutput&lt;T>[] | Promise&lt;InferSchemaOutput&lt;T>[]>, TError, TQueryKey, TKey, T, InferSchemaOutput&lt;T>[]> & object

Query 컬렉션의 구성 옵션입니다.

반환값

CollectionConfig&lt;InferSchemaOutput&lt;T>, TKey, T, QueryCollectionUtils&lt;InferSchemaOutput&lt;T>, TKey, InferSchemaInput&lt;T>, TError>> & object

직접 쓰기 및 수동 작업을 위한 유틸리티가 포함된 컬렉션 옵션입니다.

예시

// Type inferred from queryFn return type (NEW!)
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => {
const response = await fetch('/api/todos')
return response.json() as Todo[] // Type automatically inferred!
},
queryClient,
getKey: (item) => item.id, // item is typed as Todo
})
)
// Explicit type
const todosCollection = createCollection<Todo>(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
queryClient,
getKey: (item) => item.id,
})
)
// Schema inference
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
queryClient,
schema: todoSchema, // Type inferred from schema
getKey: (item) => item.id,
})
)
// With persistence handlers
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: fetchTodos,
queryClient,
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
await api.createTodos(transaction.mutations.map(m => m.modified))
},
onUpdate: async ({ transaction }) => {
await api.updateTodos(transaction.mutations)
},
onDelete: async ({ transaction }) => {
await api.deleteTodos(transaction.mutations.map(m => m.key))
}
})
)
// The select option extracts the items array from a response with metadata
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
select: (data) => data.items, // Extract the array of items
queryClient,
schema: todoSchema,
getKey: (item) => item.id,
})
)

호출 시그니처

function queryCollectionOptions<T, TError, TQueryKey, TKey>(config): CollectionConfig<T, TKey, never, QueryCollectionUtils<T, TKey, T, TError>> & object;

정의 위치: packages/query-db-collection/src/query.ts:637

표준 컬렉션과 함께 사용할 쿼리 컬렉션 옵션을 생성합니다. 자동 동기화를 위해 TanStack Query를 TanStack DB와 통합합니다.

다음 우선순위에 따라 자동 타입 추론을 지원합니다.

  1. 스키마 추론(최우선)
  2. QueryFn 반환 타입 추론(두 번째 우선순위)

타입 매개변수

T

T extends object

스키마가 제공된 경우 스키마의 타입이며, 그렇지 않으면 queryFn이 반환하는 값의 타입입니다.

TError

TError = unknown

쿼리 중 발생할 수 있는 오류의 타입입니다.

TQueryKey

TQueryKey 확장 readonly unknown[] = readonly unknown[]

쿼리 키의 타입입니다.

TKey

TKey 확장 string | number = string | number

항목 키의 타입입니다.

매개변수

config

QueryCollectionConfig&lt;T, (context) => T[] | Promise&lt;T[]>, TError, TQueryKey, TKey, never, T[]> & object

Query 컬렉션의 구성 옵션입니다.

반환값

CollectionConfig&lt;T, TKey, never, QueryCollectionUtils&lt;T, TKey, T, TError>> & object

직접 쓰기 및 수동 작업을 위한 유틸리티가 포함된 컬렉션 옵션입니다.

예시

// Type inferred from queryFn return type (NEW!)
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => {
const response = await fetch('/api/todos')
return response.json() as Todo[] // Type automatically inferred!
},
queryClient,
getKey: (item) => item.id, // item is typed as Todo
})
)
// Explicit type
const todosCollection = createCollection<Todo>(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
queryClient,
getKey: (item) => item.id,
})
)
// Schema inference
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
queryClient,
schema: todoSchema, // Type inferred from schema
getKey: (item) => item.id,
})
)
// With persistence handlers
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: fetchTodos,
queryClient,
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
await api.createTodos(transaction.mutations.map(m => m.modified))
},
onUpdate: async ({ transaction }) => {
await api.updateTodos(transaction.mutations)
},
onDelete: async ({ transaction }) => {
await api.deleteTodos(transaction.mutations.map(m => m.key))
}
})
)
// The select option extracts the items array from a response with metadata
const todosCollection = createCollection(
queryCollectionOptions({
queryKey: ['todos'],
queryFn: async () => fetch('/api/todos').then(r => r.json()),
select: (data) => data.items, // Extract the array of items
queryClient,
schema: todoSchema,
getKey: (item) => item.id,
})
)