함수: createCollection()
호출 시그니처
function createCollection<T, TKey, TUtils>(options): Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & NonSingleResult;
정의 위치: packages/db/src/collection/index.ts:143
지정된 구성으로 새 Collection 인스턴스를 생성합니다
타입 매개변수
T
T 확장 StandardSchemaV1<unknown, unknown>
스키마가 제공된 경우 스키마 타입이고, 그렇지 않으면 컬렉션에 있는 항목의 타입입니다
TKey
TKey 확장 string | number
컬렉션 키의 타입입니다
TUtils
TUtils 확장 UtilsRecord
유틸리티 레코드 타입입니다
매개변수
options
Omit<CollectionConfig<InferSchemaOutput<T>, TKey, T, TUtils>, "utils"> & object & NonSingleResult
선택적 유틸리티가 포함된 컬렉션 옵션입니다
반환값
Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & NonSingleResult
유틸리티가 최상위 수준과 .utils 아래 모두에 노출되는 새 Collection입니다
예시
// Pattern 1: With operation handlers (direct collection calls)
const todos = createCollection({
id: "todos",
getKey: (todo) => todo.id,
schema,
onInsert: async ({ transaction, collection }) => {
// Send to API
await api.createTodo(transaction.mutations[0].modified)
},
onUpdate: async ({ transaction, collection }) => {
await api.updateTodo(transaction.mutations[0].modified)
},
onDelete: async ({ transaction, collection }) => {
await api.deleteTodo(transaction.mutations[0].key)
},
sync: { sync: () => {} }
})
// Direct usage (handlers manage transactions)
const tx = todos.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Pattern 2: Manual transaction management
const todos = createCollection({
getKey: (todo) => todo.id,
schema: todoSchema,
sync: { sync: () => {} }
})
// Explicit transaction usage
const tx = createTransaction({
mutationFn: async ({ transaction }) => {
// Handle all mutations in transaction
await api.saveChanges(transaction.mutations)
}
})
tx.mutate(() => {
todos.insert({ id: "1", text: "Buy milk" })
todos.update("2", draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Using schema for type inference (preferred as it also gives you client side validation)
const todoSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean()
})
const todos = createCollection({
schema: todoSchema,
getKey: (todo) => todo.id,
sync: { sync: () => {} }
})
호출 시그니처
function createCollection<T, TKey, TUtils>(options): Collection<InferSchemaOutput<T>, TKey, Exclude<TUtils, undefined>, T, InferSchemaInput<T>> & NonSingleResult;
정의 위치: packages/db/src/collection/index.ts:160
지정된 구성으로 새 Collection 인스턴스를 생성합니다
타입 매개변수
T
T 확장 StandardSchemaV1<unknown, unknown>
스키마가 제공된 경우 스키마 타입이고, 그렇지 않으면 컬렉션에 있는 항목의 타입입니다
TKey
TKey 확장 string | number
컬렉션 키의 타입입니다
TUtils
TUtils 확장 UtilsRecord
유틸리티 레코드 타입입니다
매개변수
options
CollectionConfig<InferSchemaOutput<T>, TKey, T, TUtils> & object & NonSingleResult
선택적 유틸리티가 포함된 컬렉션 옵션입니다
반환값
Collection<InferSchemaOutput<T>, TKey, Exclude<TUtils, undefined>, T, InferSchemaInput<T>> & NonSingleResult
유틸리티가 최상위 수준과 .utils 아래 모두에 노출되는 새 Collection입니다
예시
// Pattern 1: With operation handlers (direct collection calls)
const todos = createCollection({
id: "todos",
getKey: (todo) => todo.id,
schema,
onInsert: async ({ transaction, collection }) => {
// Send to API
await api.createTodo(transaction.mutations[0].modified)
},
onUpdate: async ({ transaction, collection }) => {
await api.updateTodo(transaction.mutations[0].modified)
},
onDelete: async ({ transaction, collection }) => {
await api.deleteTodo(transaction.mutations[0].key)
},
sync: { sync: () => {} }
})
// Direct usage (handlers manage transactions)
const tx = todos.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Pattern 2: Manual transaction management
const todos = createCollection({
getKey: (todo) => todo.id,
schema: todoSchema,
sync: { sync: () => {} }
})
// Explicit transaction usage
const tx = createTransaction({
mutationFn: async ({ transaction }) => {
// Handle all mutations in transaction
await api.saveChanges(transaction.mutations)
}
})
tx.mutate(() => {
todos.insert({ id: "1", text: "Buy milk" })
todos.update("2", draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Using schema for type inference (preferred as it also gives you client side validation)
const todoSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean()
})
const todos = createCollection({
schema: todoSchema,
getKey: (todo) => todo.id,
sync: { sync: () => {} }
})
호출 시그니처
function createCollection<T, TKey, TUtils>(options): Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & SingleResult;
정의 위치: packages/db/src/collection/index.ts:178
지정된 구성으로 새 Collection 인스턴스를 생성합니다
타입 매개변수
T
T 확장 StandardSchemaV1<unknown, unknown>
스키마가 제공된 경우 스키마 타입이고, 그렇지 않으면 컬렉션에 있는 항목의 타입입니다
TKey
TKey 확장 string | number
컬렉션 키의 타입입니다
TUtils
TUtils 확장 UtilsRecord
유틸리티 레코드 타입입니다
매개변수
options
Omit<CollectionConfig<InferSchemaOutput<T>, TKey, T, TUtils>, "utils"> & object & SingleResult
선택적 유틸리티가 포함된 컬렉션 옵션입니다
반환값
Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & SingleResult
유틸리티가 최상위 수준과 .utils 아래 모두에 노출되는 새 Collection입니다
예시
// Pattern 1: With operation handlers (direct collection calls)
const todos = createCollection({
id: "todos",
getKey: (todo) => todo.id,
schema,
onInsert: async ({ transaction, collection }) => {
// Send to API
await api.createTodo(transaction.mutations[0].modified)
},
onUpdate: async ({ transaction, collection }) => {
await api.updateTodo(transaction.mutations[0].modified)
},
onDelete: async ({ transaction, collection }) => {
await api.deleteTodo(transaction.mutations[0].key)
},
sync: { sync: () => {} }
})
// Direct usage (handlers manage transactions)
const tx = todos.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Pattern 2: Manual transaction management
const todos = createCollection({
getKey: (todo) => todo.id,
schema: todoSchema,
sync: { sync: () => {} }
})
// Explicit transaction usage
const tx = createTransaction({
mutationFn: async ({ transaction }) => {
// Handle all mutations in transaction
await api.saveChanges(transaction.mutations)
}
})
tx.mutate(() => {
todos.insert({ id: "1", text: "Buy milk" })
todos.update("2", draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Using schema for type inference (preferred as it also gives you client side validation)
const todoSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean()
})
const todos = createCollection({
schema: todoSchema,
getKey: (todo) => todo.id,
sync: { sync: () => {} }
})
호출 시그니처
function createCollection<T, TKey, TUtils>(options): Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & SingleResult;
정의 위치: packages/db/src/collection/index.ts:194
지정된 구성으로 새 Collection 인스턴스를 생성합니다
타입 매개변수
T
T 확장 StandardSchemaV1<unknown, unknown>
스키마가 제공된 경우 스키마 타입이고, 그렇지 않으면 컬렉션에 있는 항목의 타입입니다
TKey
TKey 확장 string | number
컬렉션 키의 타입입니다
TUtils
TUtils 확장 UtilsRecord
유틸리티 레코드 타입입니다
매개변수
options
CollectionConfig<InferSchemaOutput<T>, TKey, T, TUtils> & object & SingleResult
선택적 유틸리티가 포함된 컬렉션 옵션입니다
반환값
Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & SingleResult
유틸리티가 최상위 수준과 .utils 아래 모두에 노출되는 새 Collection입니다
예시
// Pattern 1: With operation handlers (direct collection calls)
const todos = createCollection({
id: "todos",
getKey: (todo) => todo.id,
schema,
onInsert: async ({ transaction, collection }) => {
// Send to API
await api.createTodo(transaction.mutations[0].modified)
},
onUpdate: async ({ transaction, collection }) => {
await api.updateTodo(transaction.mutations[0].modified)
},
onDelete: async ({ transaction, collection }) => {
await api.deleteTodo(transaction.mutations[0].key)
},
sync: { sync: () => {} }
})
// Direct usage (handlers manage transactions)
const tx = todos.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Pattern 2: Manual transaction management
const todos = createCollection({
getKey: (todo) => todo.id,
schema: todoSchema,
sync: { sync: () => {} }
})
// Explicit transaction usage
const tx = createTransaction({
mutationFn: async ({ transaction }) => {
// Handle all mutations in transaction
await api.saveChanges(transaction.mutations)
}
})
tx.mutate(() => {
todos.insert({ id: "1", text: "Buy milk" })
todos.update("2", draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Using schema for type inference (preferred as it also gives you client side validation)
const todoSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean()
})
const todos = createCollection({
schema: todoSchema,
getKey: (todo) => todo.id,
sync: { sync: () => {} }
})
호출 시그니처
function createCollection<T, TKey, TUtils>(options): Collection<T, TKey, TUtils, never, T> & NonSingleResult;
정의 위치: packages/db/src/collection/index.ts:207
지정된 구성으로 새 Collection 인스턴스를 생성합니다
타입 매개변수
T
T 확장 object
스키마가 제공된 경우 스키마 타입이고, 그렇지 않으면 컬렉션에 있는 항목의 타입입니다
TKey
TKey 확장 string | number
컬렉션 키의 타입입니다
TUtils
TUtils 확장 UtilsRecord
유틸리티 레코드 타입입니다
매개변수
options
Omit<CollectionConfig<T, TKey, never, TUtils>, "utils"> & object & NonSingleResult
선택적 유틸리티가 포함된 컬렉션 옵션입니다
반환값
Collection<T, TKey, TUtils, never, T> & NonSingleResult
유틸리티가 최상위 수준과 .utils 아래 모두에 노출되는 새 Collection입니다
예시
// Pattern 1: With operation handlers (direct collection calls)
const todos = createCollection({
id: "todos",
getKey: (todo) => todo.id,
schema,
onInsert: async ({ transaction, collection }) => {
// Send to API
await api.createTodo(transaction.mutations[0].modified)
},
onUpdate: async ({ transaction, collection }) => {
await api.updateTodo(transaction.mutations[0].modified)
},
onDelete: async ({ transaction, collection }) => {
await api.deleteTodo(transaction.mutations[0].key)
},
sync: { sync: () => {} }
})
// Direct usage (handlers manage transactions)
const tx = todos.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Pattern 2: Manual transaction management
const todos = createCollection({
getKey: (todo) => todo.id,
schema: todoSchema,
sync: { sync: () => {} }
})
// Explicit transaction usage
const tx = createTransaction({
mutationFn: async ({ transaction }) => {
// Handle all mutations in transaction
await api.saveChanges(transaction.mutations)
}
})
tx.mutate(() => {
todos.insert({ id: "1", text: "Buy milk" })
todos.update("2", draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Using schema for type inference (preferred as it also gives you client side validation)
const todoSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean()
})
const todos = createCollection({
schema: todoSchema,
getKey: (todo) => todo.id,
sync: { sync: () => {} }
})
호출 시그니처
function createCollection<T, TKey, TUtils>(options): Collection<T, TKey, TUtils, never, T> & NonSingleResult;
정의 위치: packages/db/src/collection/index.ts:220
지정된 구성으로 새 Collection 인스턴스를 생성합니다
타입 매개변수
T
T extends object
스키마가 제공된 경우 스키마 타입이고, 그렇지 않으면 컬렉션에 있는 항목의 타입입니다
TKey
TKey 확장 string | number = string | number
컬렉션 키의 타입입니다
TUtils
TUtils 확장 UtilsRecord = UtilsRecord
유틸리티 레코드 타입입니다
매개변수
options
CollectionConfig<T, TKey, never, TUtils> & object & NonSingleResult
선택적 유틸리티가 포함된 컬렉션 옵션입니다
반환값
Collection<T, TKey, TUtils, never, T> & NonSingleResult
유틸리티가 최상위 수준과 .utils 아래 모두에 노출되는 새 Collection입니다
예시
// Pattern 1: With operation handlers (direct collection calls)
const todos = createCollection({
id: "todos",
getKey: (todo) => todo.id,
schema,
onInsert: async ({ transaction, collection }) => {
// Send to API
await api.createTodo(transaction.mutations[0].modified)
},
onUpdate: async ({ transaction, collection }) => {
await api.updateTodo(transaction.mutations[0].modified)
},
onDelete: async ({ transaction, collection }) => {
await api.deleteTodo(transaction.mutations[0].key)
},
sync: { sync: () => {} }
})
// Direct usage (handlers manage transactions)
const tx = todos.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Pattern 2: Manual transaction management
const todos = createCollection({
getKey: (todo) => todo.id,
schema: todoSchema,
sync: { sync: () => {} }
})
// Explicit transaction usage
const tx = createTransaction({
mutationFn: async ({ transaction }) => {
// Handle all mutations in transaction
await api.saveChanges(transaction.mutations)
}
})
tx.mutate(() => {
todos.insert({ id: "1", text: "Buy milk" })
todos.update("2", draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Using schema for type inference (preferred as it also gives you client side validation)
const todoSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean()
})
const todos = createCollection({
schema: todoSchema,
getKey: (todo) => todo.id,
sync: { sync: () => {} }
})
호출 시그니처
function createCollection<T, TKey, TUtils>(options): Collection<T, TKey, TUtils, never, T> & SingleResult;
정의 위치: packages/db/src/collection/index.ts:232
지정된 구성으로 새 Collection 인스턴스를 생성합니다
타입 매개변수
T
T 확장 object
스키마가 제공된 경우 스키마 타입이고, 그렇지 않으면 컬렉션에 있는 항목의 타입입니다
TKey
TKey 확장 string | number = string | number
컬렉션 키의 타입입니다
TUtils
TUtils 확장 UtilsRecord = UtilsRecord
유틸리티 레코드 타입입니다
매개변수
options
Omit<CollectionConfig<T, TKey, never, TUtils>, "utils"> & object & SingleResult
선택적 유틸리티가 포함된 컬렉션 옵션입니다
반환값
Collection<T, TKey, TUtils, never, T> & SingleResult
유틸리티가 최상위 수준과 .utils 아래 모두에 노출되는 새 Collection입니다
예시
// Pattern 1: With operation handlers (direct collection calls)
const todos = createCollection({
id: "todos",
getKey: (todo) => todo.id,
schema,
onInsert: async ({ transaction, collection }) => {
// Send to API
await api.createTodo(transaction.mutations[0].modified)
},
onUpdate: async ({ transaction, collection }) => {
await api.updateTodo(transaction.mutations[0].modified)
},
onDelete: async ({ transaction, collection }) => {
await api.deleteTodo(transaction.mutations[0].key)
},
sync: { sync: () => {} }
})
// Direct usage (handlers manage transactions)
const tx = todos.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Pattern 2: Manual transaction management
const todos = createCollection({
getKey: (todo) => todo.id,
schema: todoSchema,
sync: { sync: () => {} }
})
// Explicit transaction usage
const tx = createTransaction({
mutationFn: async ({ transaction }) => {
// Handle all mutations in transaction
await api.saveChanges(transaction.mutations)
}
})
tx.mutate(() => {
todos.insert({ id: "1", text: "Buy milk" })
todos.update("2", draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Using schema for type inference (preferred as it also gives you client side validation)
const todoSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean()
})
const todos = createCollection({
schema: todoSchema,
getKey: (todo) => todo.id,
sync: { sync: () => {} }
})
호출 시그니처
function createCollection<T, TKey, TUtils>(options): Collection<T, TKey, TUtils, never, T> & SingleResult;
정의 위치: packages/db/src/collection/index.ts:245
지정된 구성으로 새 Collection 인스턴스를 생성합니다
타입 매개변수
T
T 확장 object
스키마가 제공된 경우 스키마 타입이고, 그렇지 않으면 컬렉션에 있는 항목의 타입입니다
TKey
TKey 확장 string | number = string | number
컬렉션 키의 타입입니다
TUtils
TUtils 확장 UtilsRecord = UtilsRecord
유틸리티 레코드 타입입니다
매개변수
options
CollectionConfig<T, TKey, never, TUtils> & object & SingleResult
선택적 유틸리티가 포함된 컬렉션 옵션입니다
반환값
Collection<T, TKey, TUtils, never, T> & SingleResult
유틸리티가 최상위 수준과 .utils 아래 모두에 노출되는 새 Collection입니다
예시
// Pattern 1: With operation handlers (direct collection calls)
const todos = createCollection({
id: "todos",
getKey: (todo) => todo.id,
schema,
onInsert: async ({ transaction, collection }) => {
// Send to API
await api.createTodo(transaction.mutations[0].modified)
},
onUpdate: async ({ transaction, collection }) => {
await api.updateTodo(transaction.mutations[0].modified)
},
onDelete: async ({ transaction, collection }) => {
await api.deleteTodo(transaction.mutations[0].key)
},
sync: { sync: () => {} }
})
// Direct usage (handlers manage transactions)
const tx = todos.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Pattern 2: Manual transaction management
const todos = createCollection({
getKey: (todo) => todo.id,
schema: todoSchema,
sync: { sync: () => {} }
})
// Explicit transaction usage
const tx = createTransaction({
mutationFn: async ({ transaction }) => {
// Handle all mutations in transaction
await api.saveChanges(transaction.mutations)
}
})
tx.mutate(() => {
todos.insert({ id: "1", text: "Buy milk" })
todos.update("2", draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Using schema for type inference (preferred as it also gives you client side validation)
const todoSchema = z.object({
id: z.string(),
title: z.string(),
completed: z.boolean()
})
const todos = createCollection({
schema: todoSchema,
getKey: (todo) => todo.id,
sync: { sync: () => {} }
})