Definiert in: packages/electric-db-collection/src/electric.ts:73
Konfigurationsschnittstelle für Optionen von Electric-Kollektionen
Typauflösung folgt einer Prioritätsreihenfolge
Sie sollten ENTWEDER einen expliziten Typ ODER ein Schema angeben, aber nicht beides, da dies zu Konflikten führen würde.
• TExplicit erweitert Row<unknown> = Row<unknown>
Der explizite Typ der Elemente in der Collection (höchste Priorität)
• TSchema erweitert StandardSchemaV1 = never
Der Schema-Typ für Validierung und Typableitung (zweite Priorität)
• TFallback erweitert Row<unknown> = Row<unknown>
Der Fallback-Typ, wenn kein expliziter Typ oder kein Schema-Typ angegeben wird
getKey: (item) => string | number;
getKey: (item) => string | number;
Definiert in: packages/electric-db-collection/src/electric.ts:90
ResolveType
string | number
optional id: string;
optional id: string;
Definiert in: packages/electric-db-collection/src/electric.ts:88
Alle Standard-Konfigurationseigenschaften der Collection
optional onDelete: (params) => Promise<{
txid: number | number[];
}>;
optional onDelete: (params) => Promise<{
txid: number | number[];
}>;
Definiert in: packages/electric-db-collection/src/electric.ts:246
Optionale asynchrone Handler-Funktion, die vor einer Löschoperation aufgerufen wird. Muss ein Objekt mit einer txid-Nummer oder einem Array von txids zurückgeben.
DeleteMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Objekt, das Transaktions- und Collection-Informationen enthält
Promise<{ txid: number | number[]; }>
Promise, das zu einem Objekt mit txid oder txids aufgelöst wird
// Basic Electric delete handler - MUST return { txid: number }
onDelete: async ({ transaction }) => {
const mutation = transaction.mutations[0]
const result = await api.todos.delete({
id: mutation.original.id
})
return { txid: result.txid } // Required for Electric sync matching
}
// Basic Electric delete handler - MUST return { txid: number }
onDelete: async ({ transaction }) => {
const mutation = transaction.mutations[0]
const result = await api.todos.delete({
id: mutation.original.id
})
return { txid: result.txid } // Required for Electric sync matching
}
// Delete handler with multiple items - return array of txids
onDelete: async ({ transaction }) => {
const deletes = await Promise.all(
transaction.mutations.map(m =>
api.todos.delete({
where: { id: m.key }
})
)
)
return { txid: deletes.map(d => d.txid) } // Array of txids
}
// Delete handler with multiple items - return array of txids
onDelete: async ({ transaction }) => {
const deletes = await Promise.all(
transaction.mutations.map(m =>
api.todos.delete({
where: { id: m.key }
})
)
)
return { txid: deletes.map(d => d.txid) } // Array of txids
}
// Delete handler with batch operation - single txid
onDelete: async ({ transaction }) => {
const idsToDelete = transaction.mutations.map(m => m.original.id)
const result = await api.todos.deleteMany({
ids: idsToDelete
})
return { txid: result.txid } // Single txid for batch operation
}
// Delete handler with batch operation - single txid
onDelete: async ({ transaction }) => {
const idsToDelete = transaction.mutations.map(m => m.original.id)
const result = await api.todos.deleteMany({
ids: idsToDelete
})
return { txid: result.txid } // Single txid for batch operation
}
// Delete handler with optimistic rollback
onDelete: async ({ transaction }) => {
const mutation = transaction.mutations[0]
try {
const result = await api.deleteTodo(mutation.original.id)
return { txid: result.txid }
} catch (error) {
// Transaction will automatically rollback optimistic changes
console.error('Delete failed, rolling back:', error)
throw error
}
}
// Delete handler with optimistic rollback
onDelete: async ({ transaction }) => {
const mutation = transaction.mutations[0]
try {
const result = await api.deleteTodo(mutation.original.id)
return { txid: result.txid }
} catch (error) {
// Transaction will automatically rollback optimistic changes
console.error('Delete failed, rolling back:', error)
throw error
}
}
optional onInsert: (params) => Promise<{
txid: number | number[];
}>;
optional onInsert: (params) => Promise<{
txid: number | number[];
}>;
Definiert in: packages/electric-db-collection/src/electric.ts:141
Optionaler asynchroner Handler, der vor einer Einfügeoperation aufgerufen wird. Muss ein Objekt mit einer txid-Nummer oder einem Array von txids zurückgeben.
InsertMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Objekt, das Transaktions- und Collection-Informationen enthält
Promise<{ txid: number | number[]; }>
Promise, das zu einem Objekt mit txid oder txids aufgelöst wird
// Basic Electric insert handler - MUST return { txid: number }
onInsert: async ({ transaction }) => {
const newItem = transaction.mutations[0].modified
const result = await api.todos.create({
data: newItem
})
return { txid: result.txid } // Required for Electric sync matching
}
// Basic Electric insert handler - MUST return { txid: number }
onInsert: async ({ transaction }) => {
const newItem = transaction.mutations[0].modified
const result = await api.todos.create({
data: newItem
})
return { txid: result.txid } // Required for Electric sync matching
}
// 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) } // Array of txids
}
// 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) } // Array of txids
}
// Insert handler with error handling
onInsert: async ({ transaction }) => {
try {
const newItem = transaction.mutations[0].modified
const result = await api.createTodo(newItem)
return { txid: result.txid }
} catch (error) {
console.error('Insert failed:', error)
throw error // This will cause the transaction to fail
}
}
// Insert handler with error handling
onInsert: async ({ transaction }) => {
try {
const newItem = transaction.mutations[0].modified
const result = await api.createTodo(newItem)
return { txid: result.txid }
} catch (error) {
console.error('Insert failed:', error)
throw error // This will cause the transaction to fail
}
}
// Insert handler with batch operation - single txid
onInsert: async ({ transaction }) => {
const items = transaction.mutations.map(m => m.modified)
const result = await api.todos.createMany({
data: items
})
return { txid: result.txid } // Single txid for batch operation
}
// Insert handler with batch operation - single txid
onInsert: async ({ transaction }) => {
const items = transaction.mutations.map(m => m.modified)
const result = await api.todos.createMany({
data: items
})
return { txid: result.txid } // Single txid for batch operation
}
optional onUpdate: (params) => Promise<{
txid: number | number[];
}>;
optional onUpdate: (params) => Promise<{
txid: number | number[];
}>;
Definiert in: packages/electric-db-collection/src/electric.ts:189
Optionaler asynchroner Handler, der vor einer Update-Operation aufgerufen wird. Muss ein Objekt mit einer txid-Nummer oder einem Array von txids zurückgeben.
UpdateMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Objekt, das Transaktions- und Collection-Informationen enthält
Promise<{ txid: number | number[]; }>
Promise, das zu einem Objekt mit txid oder txids aufgelöst wird
// Basic Electric update handler - MUST return { txid: number }
onUpdate: async ({ transaction }) => {
const { original, changes } = transaction.mutations[0]
const result = await api.todos.update({
where: { id: original.id },
data: changes // Only the changed fields
})
return { txid: result.txid } // Required for Electric sync matching
}
// Basic Electric update handler - MUST return { txid: number }
onUpdate: async ({ transaction }) => {
const { original, changes } = transaction.mutations[0]
const result = await api.todos.update({
where: { id: original.id },
data: changes // Only the changed fields
})
return { txid: result.txid } // Required for Electric sync matching
}
// Update handler with multiple items - return array of txids
onUpdate: async ({ transaction }) => {
const updates = await Promise.all(
transaction.mutations.map(m =>
api.todos.update({
where: { id: m.original.id },
data: m.changes
})
)
)
return { txid: updates.map(u => u.txid) } // Array of txids
}
// Update handler with multiple items - return array of txids
onUpdate: async ({ transaction }) => {
const updates = await Promise.all(
transaction.mutations.map(m =>
api.todos.update({
where: { id: m.original.id },
data: m.changes
})
)
)
return { txid: updates.map(u => u.txid) } // Array of txids
}
// Update handler with optimistic rollback
onUpdate: async ({ transaction }) => {
const mutation = transaction.mutations[0]
try {
const result = await api.updateTodo(mutation.original.id, mutation.changes)
return { txid: result.txid }
} catch (error) {
// Transaction will automatically rollback optimistic changes
console.error('Update failed, rolling back:', error)
throw error
}
}
// Update handler with optimistic rollback
onUpdate: async ({ transaction }) => {
const mutation = transaction.mutations[0]
try {
const result = await api.updateTodo(mutation.original.id, mutation.changes)
return { txid: result.txid }
} catch (error) {
// Transaction will automatically rollback optimistic changes
console.error('Update failed, rolling back:', error)
throw error
}
}
optional schema: TSchema;
optional schema: TSchema;
Definiert in: packages/electric-db-collection/src/electric.ts:89
shapeOptions: ShapeStreamOptions<GetExtensions<ResolveType<TExplicit, TSchema, TFallback>>>;
shapeOptions: ShapeStreamOptions<GetExtensions<ResolveType<TExplicit, TSchema, TFallback>>>;
Definiert in: packages/electric-db-collection/src/electric.ts:81
Konfigurationsoptionen für den ElectricSQL ShapeStream
optional sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, string | number>;
optional sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, string | number>;
Definiert in: packages/electric-db-collection/src/electric.ts:91
Ihre wöchentliche Dosis JavaScript-Nachrichten. Jeden Montag kostenlos an über 100.000 Entwickler geliefert.