인터페이스: ElectricCollectionConfig<T, TSchema>
정의 위치: packages/electric-db-collection/src/electric.ts:281
Electric 컬렉션 옵션의 구성 인터페이스입니다.
상속
Omit<BaseCollectionConfig<T,string|number,TSchema,ElectricCollectionUtils<T>,any>,"onInsert"|"onUpdate"|"onDelete"|"syncMode">
타입 매개변수
T
T extends Row<unknown> = Row<unknown>
컬렉션 항목의 타입입니다.
TSchema
TSchema extends StandardSchemaV1 = never
검증을 위한 스키마 타입
속성
[ELECTRIC_TEST_HOOKS]?
optional [ELECTRIC_TEST_HOOKS]: ElectricTestHooks;
정의 위치: packages/electric-db-collection/src/electric.ts:304
내부 테스트 훅(테스트 전용) 프로덕션에서 실수로 사용하지 않도록 Symbol을 통해 숨겨집니다
onDelete()?
optional onDelete: (params) => Promise<MatchingStrategy>;
정의 위치: packages/electric-db-collection/src/electric.ts:421
삭제 작업 전에 호출되는 선택적 비동기 핸들러 함수
매개변수
params
DeleteMutationFnParams<T, string | number, ElectricCollectionUtils<T>>
트랜잭션 및 컬렉션 정보가 포함된 객체
반환값
Promise<MatchingStrategy>
{ txid, timeout? } 또는 void로 확인되는 Promise입니다.
예제
// Basic Electric delete handler with txid (recommended)
onDelete: async ({ transaction }) => {
const mutation = transaction.mutations[0]
const result = await api.todos.delete({
id: mutation.original.id
})
return { txid: result.txid }
}
// Use awaitMatch utility for custom matching
onDelete: async ({ transaction, collection }) => {
const mutation = transaction.mutations[0]
await api.todos.delete({ id: mutation.original.id })
await collection.utils.awaitMatch(
(message) => isChangeMessage(message) &&
message.headers.operation === 'delete' &&
message.value.id === mutation.original.id
)
}
onInsert()?
optional onInsert: (params) => Promise<MatchingStrategy>;
정의 위치: packages/electric-db-collection/src/electric.ts:352
삽입 작업 전에 호출되는 선택적 비동기 핸들러 함수
매개변수
params
InsertMutationFnParams<T, string | number, ElectricCollectionUtils<T>>
트랜잭션 및 컬렉션 정보가 포함된 객체
반환값
Promise<MatchingStrategy>
{ txid, timeout? } 또는 void로 확인되는 Promise입니다.
예제
// Basic Electric insert handler with txid (recommended)
onInsert: async ({ transaction }) => {
const newItem = transaction.mutations[0].modified
const result = await api.todos.create({
data: newItem
})
return { txid: result.txid }
}
// Insert handler with custom timeout
onInsert: async ({ transaction }) => {
const newItem = transaction.mutations[0].modified
const result = await api.todos.create({
data: newItem
})
return { txid: result.txid, timeout: 10000 } // Wait up to 10 seconds
}
// Insert handler with multiple items - return array of txids
onInsert: async ({ transaction }) => {
const items = transaction.mutations.map(m => m.modified)
const results = await Promise.all(
items.map(item => api.todos.create({ data: item }))
)
return { txid: results.map(r => r.txid) }
}
// Use awaitMatch utility for custom matching
onInsert: async ({ transaction, collection }) => {
const newItem = transaction.mutations[0].modified
await api.todos.create({ data: newItem })
await collection.utils.awaitMatch(
(message) => isChangeMessage(message) &&
message.headers.operation === 'insert' &&
message.value.name === newItem.name
)
}
onUpdate()?
optional onUpdate: (params) => Promise<MatchingStrategy>;
정의 위치: packages/electric-db-collection/src/electric.ts:387
업데이트 작업 전에 호출되는 선택적 비동기 핸들러 함수
매개변수
params
UpdateMutationFnParams<T, string | number, ElectricCollectionUtils<T>>
트랜잭션 및 컬렉션 정보가 포함된 객체
반환값
Promise<MatchingStrategy>
{ txid, timeout? } 또는 void로 확인되는 Promise입니다.
예제
// Basic Electric update handler with txid (recommended)
onUpdate: async ({ transaction }) => {
const { original, changes } = transaction.mutations[0]
const result = await api.todos.update({
where: { id: original.id },
data: changes
})
return { txid: result.txid }
}
// Use awaitMatch utility for custom matching
onUpdate: async ({ transaction, collection }) => {
const { original, changes } = transaction.mutations[0]
await api.todos.update({ where: { id: original.id }, data: changes })
await collection.utils.awaitMatch(
(message) => isChangeMessage(message) &&
message.headers.operation === 'update' &&
message.value.id === original.id
)
}
shapeOptions
shapeOptions: ShapeStreamOptions<GetExtensions<T>>;
정의 위치: packages/electric-db-collection/src/electric.ts:297
ElectricSQL ShapeStream의 구성 옵션
syncMode?
optional syncMode: ElectricSyncMode;