Definiert in: packages/db/src/collection.ts:204
• T extends object = Record<string, unknown>
• TKey erweitert string | number = string | number
• TUtils erweitert UtilsRecord = {}
• TSchema extends StandardSchemaV1 = StandardSchemaV1
• TInsertInput extends object = T
new CollectionImpl<T, TKey, TUtils, TSchema, TInsertInput>(config): CollectionImpl<T, TKey, TUtils, TSchema, TInsertInput>
new CollectionImpl<T, TKey, TUtils, TSchema, TInsertInput>(config): CollectionImpl<T, TKey, TUtils, TSchema, TInsertInput>
Definiert in: packages/db/src/collection.ts:407
Erstellt eine neue Collection-Instanz
CollectionConfig<T, TKey, TSchema, TInsertInput>
Konfigurationsobjekt für die Collection
CollectionImpl<T, TKey, TUtils, TSchema, TInsertInput>
Fehler, wenn die Sync-Konfiguration fehlt
config: CollectionConfig<T, TKey, TSchema, TInsertInput>;
config: CollectionConfig<T, TKey, TSchema, TInsertInput>;
Definiert in: packages/db/src/collection.ts:211
id: string;
id: string;
Definiert in: packages/db/src/collection.ts:331
optimisticDeletes: Set<TKey>;
optimisticDeletes: Set<TKey>;
Definiert in: packages/db/src/collection.ts:221
optimisticUpserts: Map<TKey, T>;
optimisticUpserts: Map<TKey, T>;
Definiert in: packages/db/src/collection.ts:220
pendingSyncedTransactions: PendingSyncedTransaction<T>[] = [];
pendingSyncedTransactions: PendingSyncedTransaction<T>[] = [];
Definiert in: packages/db/src/collection.ts:215
syncedData: Map<TKey, T> | SortedMap<TKey, T>;
syncedData: Map<TKey, T> | SortedMap<TKey, T>;
Definiert in: packages/db/src/collection.ts:216
syncedMetadata: Map<TKey, unknown>;
syncedMetadata: Map<TKey, unknown>;
Definiert in: packages/db/src/collection.ts:217
transactions: SortedMap<string, Transaction<any>>;
transactions: SortedMap<string, Transaction<any>>;
Definiert in: packages/db/src/collection.ts:214
utils: Record<string, Fn> = {};
utils: Record<string, Fn> = {};
Definiert in: packages/db/src/collection.ts:238
get indexes(): Map<number, BaseIndex<TKey>>
get indexes(): Map<number, BaseIndex<TKey>>
Definiert in: packages/db/src/collection.ts:1439
Gibt aufgelöste Indizes für die Abfrageoptimierung zurück
Map<number, BaseIndex<TKey>>
get size(): number
get size(): number
Definiert in: packages/db/src/collection.ts:995
Gibt die aktuelle Größe der Collection zurück (gecached)
number
get state(): Map<TKey, T>
get state(): Map<TKey, T>
Definiert in: packages/db/src/collection.ts:2038
Ruft den aktuellen Zustand der Collection als Map ab
const itemsMap = collection.state
console.log(`Collection has ${itemsMap.size} items`)
for (const [key, item] of itemsMap) {
console.log(`${key}: ${item.title}`)
}
// Check if specific item exists
if (itemsMap.has("todo-1")) {
console.log("Todo 1 exists:", itemsMap.get("todo-1"))
}
const itemsMap = collection.state
console.log(`Collection has ${itemsMap.size} items`)
for (const [key, item] of itemsMap) {
console.log(`${key}: ${item.title}`)
}
// Check if specific item exists
if (itemsMap.has("todo-1")) {
console.log("Todo 1 exists:", itemsMap.get("todo-1"))
}
Map<TKey, T>
Map mit allen Elementen in der Collection, wobei die Schlüssel die Identifikatoren sind
get status(): CollectionStatus
get status(): CollectionStatus
Definiert in: packages/db/src/collection.ts:336
Ruft den aktuellen Status der Collection ab
get toArray(): T[]
get toArray(): T[]
Definiert in: packages/db/src/collection.ts:2071
Ruft den aktuellen Zustand der Collection als Array ab
T[]
Ein Array, das alle Elemente in der Collection enthält
iterator: IterableIterator<[TKey, T]>
iterator: IterableIterator<[TKey, T]>
Definiert in: packages/db/src/collection.ts:1046
Holt alle Einträge (virtueller abgeleiteter Zustand)
IterableIterator<[TKey, T]>
cleanup(): Promise<void>
cleanup(): Promise<void>
Definiert in: packages/db/src/collection.ts:583
Räumt die Collection auf, indem die Synchronisierung gestoppt und die Daten gelöscht werden. Kann manuell oder automatisch durch Garbage Collection aufgerufen werden.
Promise<void>
commitPendingTransactions(): void
commitPendingTransactions(): void
Definiert in: packages/db/src/collection.ts:1082
Versucht, ausstehende synchronisierte Transaktionen zu committen, wenn keine aktiven Transaktionen vorhanden sind. Diese Methode verarbeitet Operationen aus ausstehenden Transaktionen und wendet sie auf die synchronisierten Daten an.
void
createIndex<TResolver>(indexCallback, config): IndexProxy<TKey>
createIndex<TResolver>(indexCallback, config): IndexProxy<TKey>
Definiert in: packages/db/src/collection.ts:1344
Erstellt einen Index für eine Collection für schnellere Abfragen. Indizes verbessern die Abfrageleistung erheblich, indem sie Binärsuchen und Bereichsabfragen anstelle von vollständigen Scans ermöglichen.
• TResolver erweitert IndexResolver<TKey> = typeof BTreeIndex
Der Typ des Index-Resolvers (Konstruktor oder asynchroner Lader)
(row) => any
Funktion, die den indizierten Wert aus jedem Element extrahiert
IndexOptions<TResolver> = {}
Konfiguration, einschließlich Index-Typ und typenspezifischen Optionen
IndexProxy<TKey>
Ein Index-Proxy, der Zugriff auf den Index bietet, sobald er bereit ist
// Create a default B+ tree index
const ageIndex = collection.createIndex((row) => row.age)
// Create a ordered index with custom options
const ageIndex = collection.createIndex((row) => row.age, {
indexType: BTreeIndex,
options: { compareFn: customComparator },
name: 'age_btree'
})
// Create an async-loaded index
const textIndex = collection.createIndex((row) => row.content, {
indexType: async () => {
const { FullTextIndex } = await import('./indexes/fulltext.js')
return FullTextIndex
},
options: { language: 'en' }
})
// Create a default B+ tree index
const ageIndex = collection.createIndex((row) => row.age)
// Create a ordered index with custom options
const ageIndex = collection.createIndex((row) => row.age, {
indexType: BTreeIndex,
options: { compareFn: customComparator },
name: 'age_btree'
})
// Create an async-loaded index
const textIndex = collection.createIndex((row) => row.content, {
indexType: async () => {
const { FullTextIndex } = await import('./indexes/fulltext.js')
return FullTextIndex
},
options: { language: 'en' }
})
currentStateAsChanges(options): ChangeMessage<T, string | number>[]
currentStateAsChanges(options): ChangeMessage<T, string | number>[]
Definiert in: packages/db/src/collection.ts:2113
Gibt den aktuellen Zustand der Collection als Array von Änderungen zurück
CurrentStateAsChangesOptions<T> = {}
Optionen, einschließlich eines optionalen Where-Filters
ChangeMessage<T, string | number>[]
Ein Array von Änderungen
// Get all items as changes
const allChanges = collection.currentStateAsChanges()
// Get only items matching a condition
const activeChanges = collection.currentStateAsChanges({
where: (row) => row.status === 'active'
})
// Get only items using a pre-compiled expression
const activeChanges = collection.currentStateAsChanges({
whereExpression: eq(row.status, 'active')
})
// Get all items as changes
const allChanges = collection.currentStateAsChanges()
// Get only items matching a condition
const activeChanges = collection.currentStateAsChanges({
where: (row) => row.status === 'active'
})
// Get only items using a pre-compiled expression
const activeChanges = collection.currentStateAsChanges({
whereExpression: eq(row.status, 'active')
})
delete(keys, config?): Transaction<any>
delete(keys, config?): Transaction<any>
Definiert in: packages/db/src/collection.ts:1939
Löscht ein oder mehrere Elemente aus der Collection
Einzelner Schlüssel oder Array von Schlüsseln zum Löschen
TKey | TKey[]
Optionale Konfiguration, einschließlich Metadaten
Transaction<any>
Ein Transaction-Objekt, das die Löschoperation(en) darstellt
// Delete a single item
const tx = collection.delete("todo-1")
await tx.isPersisted.promise
// Delete a single item
const tx = collection.delete("todo-1")
await tx.isPersisted.promise
// Delete multiple items
const tx = collection.delete(["todo-1", "todo-2"])
await tx.isPersisted.promise
// Delete multiple items
const tx = collection.delete(["todo-1", "todo-2"])
await tx.isPersisted.promise
// Delete with metadata
const tx = collection.delete("todo-1", { metadata: { reason: "completed" } })
await tx.isPersisted.promise
// Delete with metadata
const tx = collection.delete("todo-1", { metadata: { reason: "completed" } })
await tx.isPersisted.promise
// Handle errors
try {
const tx = collection.delete("item-1")
await tx.isPersisted.promise
console.log('Delete successful')
} catch (error) {
console.log('Delete failed:', error)
}
// Handle errors
try {
const tx = collection.delete("item-1")
await tx.isPersisted.promise
console.log('Delete successful')
} catch (error) {
console.log('Delete failed:', error)
}
entries(): IterableIterator<[TKey, T]>
entries(): IterableIterator<[TKey, T]>
Definiert in: packages/db/src/collection.ts:1034
Holt alle Einträge (virtueller abgeleiteter Zustand)
IterableIterator<[TKey, T]>
forEach(callbackfn): void
forEach(callbackfn): void
Definiert in: packages/db/src/collection.ts:1055
Führt eine Rückruffunktion für jeden Eintrag in der Collection aus
(value, key, index) => void
void
generateGlobalKey(key, item): string
generateGlobalKey(key, item): string
Definiert in: packages/db/src/collection.ts:1306
any
any
string
get(key): undefined | T
get(key): undefined | T
Definiert in: packages/db/src/collection.ts:959
Ruft den aktuellen Wert für einen Schlüssel ab (virtueller abgeleiteter Zustand)
TKey
undefined | T
getKeyFromItem(item): TKey
getKeyFromItem(item): TKey
Definiert in: packages/db/src/collection.ts:1302
T
TKey
has(key): boolean
has(key): boolean
Definiert in: packages/db/src/collection.ts:977
Prüft, ob ein Schlüssel in der Collection vorhanden ist (virtueller abgeleiteter Zustand)
TKey
boolean
insert(data, config?):
| Transaction<Record<string, unknown>>
| Transaction<T>
insert(data, config?):
| Transaction<Record<string, unknown>>
| Transaction<T>
Definiert in: packages/db/src/collection.ts:1594
Fügt ein oder mehrere Elemente in die Collection ein
TInsertInput | TInsertInput[]
Optionale Konfiguration, einschließlich Metadaten
| Transaction<Record<string, unknown>> | Transaction<T>
Ein Transaction-Objekt, das die Einfügeoperation(en) darstellt
Wenn die Daten die Schema-Validierung nicht bestehen
// Insert a single todo (requires onInsert handler)
const tx = collection.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Insert a single todo (requires onInsert handler)
const tx = collection.insert({ id: "1", text: "Buy milk", completed: false })
await tx.isPersisted.promise
// Insert multiple todos at once
const tx = collection.insert([
{ id: "1", text: "Buy milk", completed: false },
{ id: "2", text: "Walk dog", completed: true }
])
await tx.isPersisted.promise
// Insert multiple todos at once
const tx = collection.insert([
{ id: "1", text: "Buy milk", completed: false },
{ id: "2", text: "Walk dog", completed: true }
])
await tx.isPersisted.promise
// Insert with metadata
const tx = collection.insert({ id: "1", text: "Buy groceries" },
{ metadata: { source: "mobile-app" } }
)
await tx.isPersisted.promise
// Insert with metadata
const tx = collection.insert({ id: "1", text: "Buy groceries" },
{ metadata: { source: "mobile-app" } }
)
await tx.isPersisted.promise
// Handle errors
try {
const tx = collection.insert({ id: "1", text: "New item" })
await tx.isPersisted.promise
console.log('Insert successful')
} catch (error) {
console.log('Insert failed:', error)
}
// Handle errors
try {
const tx = collection.insert({ id: "1", text: "New item" })
await tx.isPersisted.promise
console.log('Insert successful')
} catch (error) {
console.log('Insert failed:', error)
}
isReady(): boolean
isReady(): boolean
Definiert in: packages/db/src/collection.ts:294
Prüft, ob die Collection für die Nutzung bereit ist. Gibt true zurück, wenn die Collection von ihrer Sync-Implementierung als bereit markiert wurde.
boolean
true, wenn die Collection bereit ist, andernfalls false
if (collection.isReady()) {
console.log('Collection is ready, data is available')
// Safe to access collection.state
} else {
console.log('Collection is still loading')
}
if (collection.isReady()) {
console.log('Collection is ready, data is available')
// Safe to access collection.state
} else {
console.log('Collection is still loading')
}
keys(): IterableIterator<TKey>
keys(): IterableIterator<TKey>
Definiert in: packages/db/src/collection.ts:1002
Holt alle Schlüssel (virtueller abgeleiteter Zustand)
IterableIterator<TKey>
map<U>(callbackfn): U[]
map<U>(callbackfn): U[]
Definiert in: packages/db/src/collection.ts:1067
Erstellt ein neues Array mit den Ergebnissen des Aufrufs einer Funktion für jeden Eintrag in der Collection
• U
(value, key, index) => U
U[]
onFirstReady(callback): void
onFirstReady(callback): void
Definiert in: packages/db/src/collection.ts:272
Registriert eine Rückruffunktion, die ausgeführt werden soll, wenn die Collection zum ersten Mal bereit wird. Nützlich für das Vorladen von Collections.
() => void
Funktion, die aufgerufen werden soll, wenn die Collection zum ersten Mal bereit wird
void
collection.onFirstReady(() => {
console.log('Collection is ready for the first time')
// Safe to access collection.state now
})
collection.onFirstReady(() => {
console.log('Collection is ready for the first time')
// Safe to access collection.state now
})
onTransactionStateChange(): void
onTransactionStateChange(): void
Definiert in: packages/db/src/collection.ts:2271
Löst eine Neuberechnung aus, wenn sich Transaktionen ändern. Diese Methode sollte von der Transaction-Klasse aufgerufen werden, wenn sich der Zustand ändert.
void
preload(): Promise<void>
preload(): Promise<void>
Definiert in: packages/db/src/collection.ts:544
Lädt die Collection-Daten vor, indem die Synchronisierung gestartet wird, falls sie noch nicht gestartet wurde. Mehrere gleichzeitige Aufrufe teilen sich dasselbe Promise.
Promise<void>
startSyncImmediate(): void
startSyncImmediate(): void
Definiert in: packages/db/src/collection.ts:450
Synchronisierung sofort starten – interne Methode für kompilierte Abfragen. Dies umgeht das Lazy Loading für spezielle Fälle wie Live-Abfrageergebnisse.
void
stateWhenReady(): Promise<Map<TKey, T>>
stateWhenReady(): Promise<Map<TKey, T>>
Definiert in: packages/db/src/collection.ts:2052
Ruft den aktuellen Zustand der Collection als Map ab, löst jedoch erst auf, wenn Daten verfügbar sind. Wartet, bis der erste Sync-Commit abgeschlossen ist, bevor er aufgelöst wird.
Promise<Map<TKey, T>>
Promise, der zu einer Map mit allen Elementen in der Collection aufgelöst wird
subscribeChanges(callback, options): () => void
subscribeChanges(callback, options): () => void
Definiert in: packages/db/src/collection.ts:2158
Änderungen in der Collection abonnieren
(changes) => void
Funktion, die aufgerufen wird, wenn sich Elemente ändern
SubscribeChangesOptions<T> = {}
Abonnementoptionen, einschließlich includeInitialState und Where-Filter
Funktion
Deabonnement-Funktion – Rufen Sie diese auf, um auf Änderungen zu hören
void
// Basic subscription
const unsubscribe = collection.subscribeChanges((changes) => {
changes.forEach(change => {
console.log(`${change.type}: ${change.key}`, change.value)
})
})
// Later: unsubscribe()
// Basic subscription
const unsubscribe = collection.subscribeChanges((changes) => {
changes.forEach(change => {
console.log(`${change.type}: ${change.key}`, change.value)
})
})
// Later: unsubscribe()
// Include current state immediately
const unsubscribe = collection.subscribeChanges((changes) => {
updateUI(changes)
}, { includeInitialState: true })
// Include current state immediately
const unsubscribe = collection.subscribeChanges((changes) => {
updateUI(changes)
}, { includeInitialState: true })
// Subscribe only to changes matching a condition
const unsubscribe = collection.subscribeChanges((changes) => {
updateUI(changes)
}, {
includeInitialState: true,
where: (row) => row.status === 'active'
})
// Subscribe only to changes matching a condition
const unsubscribe = collection.subscribeChanges((changes) => {
updateUI(changes)
}, {
includeInitialState: true,
where: (row) => row.status === 'active'
})
// Subscribe using a pre-compiled expression
const unsubscribe = collection.subscribeChanges((changes) => {
updateUI(changes)
}, {
includeInitialState: true,
whereExpression: eq(row.status, 'active')
})
// Subscribe using a pre-compiled expression
const unsubscribe = collection.subscribeChanges((changes) => {
updateUI(changes)
}, {
includeInitialState: true,
whereExpression: eq(row.status, 'active')
})
subscribeChangesKey(
key,
listener,
__namedParameters): () => void
subscribeChangesKey(
key,
listener,
__namedParameters): () => void
Definiert in: packages/db/src/collection.ts:2197
Änderungen für einen bestimmten Schlüssel abonnieren
TKey
ChangeListener<T, TKey>
boolean = false
Funktion
void
toArrayWhenReady(): Promise<T[]>
toArrayWhenReady(): Promise<T[]>
Definiert in: packages/db/src/collection.ts:2081
Ruft den aktuellen Zustand der Collection als Array ab, löst jedoch erst auf, wenn Daten verfügbar sind. Wartet, bis der erste Sync-Commit abgeschlossen ist, bevor er aufgelöst wird.
Promise<T[]>
Promise, der zu einem Array mit allen Elementen in der Collection aufgelöst wird
update<TItem>(key, callback): Transaction
update<TItem>(key, callback): Transaction
Definiert in: packages/db/src/collection.ts:1725
Aktualisiert ein oder mehrere Elemente in der Collection mithilfe einer Rückruffunktion
• TItem erweitert object = T
unbekannt[]
(drafts) => void
Ein Transaction-Objekt, das die Updateoperation(en) darstellt
Wenn die aktualisierten Daten die Schema-Validierung nicht bestehen
// Update single item by key
const tx = collection.update("todo-1", (draft) => {
draft.completed = true
})
await tx.isPersisted.promise
// Update single item by key
const tx = collection.update("todo-1", (draft) => {
draft.completed = true
})
await tx.isPersisted.promise
// Update multiple items
const tx = collection.update(["todo-1", "todo-2"], (drafts) => {
drafts.forEach(draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Update multiple items
const tx = collection.update(["todo-1", "todo-2"], (drafts) => {
drafts.forEach(draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Update with metadata
const tx = collection.update("todo-1",
{ metadata: { reason: "user update" } },
(draft) => { draft.text = "Updated text" }
)
await tx.isPersisted.promise
// Update with metadata
const tx = collection.update("todo-1",
{ metadata: { reason: "user update" } },
(draft) => { draft.text = "Updated text" }
)
await tx.isPersisted.promise
// Handle errors
try {
const tx = collection.update("item-1", draft => { draft.value = "new" })
await tx.isPersisted.promise
console.log('Update successful')
} catch (error) {
console.log('Update failed:', error)
}
// Handle errors
try {
const tx = collection.update("item-1", draft => { draft.value = "new" })
await tx.isPersisted.promise
console.log('Update successful')
} catch (error) {
console.log('Update failed:', error)
}
update<TItem>(
keys,
config,
callback): Transaction
update<TItem>(
keys,
config,
callback): Transaction
Definiert in: packages/db/src/collection.ts:1731
Aktualisiert ein oder mehrere Elemente in der Collection mithilfe einer Rückruffunktion
• TItem erweitert object = T
unbekannt[]
Einzelner Schlüssel oder Array von Schlüsseln zum Aktualisieren
(drafts) => void
Ein Transaction-Objekt, das die Updateoperation(en) darstellt
Wenn die aktualisierten Daten die Schema-Validierung nicht bestehen
// Update single item by key
const tx = collection.update("todo-1", (draft) => {
draft.completed = true
})
await tx.isPersisted.promise
// Update single item by key
const tx = collection.update("todo-1", (draft) => {
draft.completed = true
})
await tx.isPersisted.promise
// Update multiple items
const tx = collection.update(["todo-1", "todo-2"], (drafts) => {
drafts.forEach(draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Update multiple items
const tx = collection.update(["todo-1", "todo-2"], (drafts) => {
drafts.forEach(draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Update with metadata
const tx = collection.update("todo-1",
{ metadata: { reason: "user update" } },
(draft) => { draft.text = "Updated text" }
)
await tx.isPersisted.promise
// Update with metadata
const tx = collection.update("todo-1",
{ metadata: { reason: "user update" } },
(draft) => { draft.text = "Updated text" }
)
await tx.isPersisted.promise
// Handle errors
try {
const tx = collection.update("item-1", draft => { draft.value = "new" })
await tx.isPersisted.promise
console.log('Update successful')
} catch (error) {
console.log('Update failed:', error)
}
// Handle errors
try {
const tx = collection.update("item-1", draft => { draft.value = "new" })
await tx.isPersisted.promise
console.log('Update successful')
} catch (error) {
console.log('Update failed:', error)
}
update<TItem>(id, callback): Transaction
update<TItem>(id, callback): Transaction
Definiert in: packages/db/src/collection.ts:1738
Aktualisiert ein oder mehrere Elemente in der Collection mithilfe einer Rückruffunktion
• TItem erweitert object = T
unbekannt
(draft) => void
Ein Transaction-Objekt, das die Updateoperation(en) darstellt
Wenn die aktualisierten Daten die Schema-Validierung nicht bestehen
// Update single item by key
const tx = collection.update("todo-1", (draft) => {
draft.completed = true
})
await tx.isPersisted.promise
// Update single item by key
const tx = collection.update("todo-1", (draft) => {
draft.completed = true
})
await tx.isPersisted.promise
// Update multiple items
const tx = collection.update(["todo-1", "todo-2"], (drafts) => {
drafts.forEach(draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Update multiple items
const tx = collection.update(["todo-1", "todo-2"], (drafts) => {
drafts.forEach(draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Update with metadata
const tx = collection.update("todo-1",
{ metadata: { reason: "user update" } },
(draft) => { draft.text = "Updated text" }
)
await tx.isPersisted.promise
// Update with metadata
const tx = collection.update("todo-1",
{ metadata: { reason: "user update" } },
(draft) => { draft.text = "Updated text" }
)
await tx.isPersisted.promise
// Handle errors
try {
const tx = collection.update("item-1", draft => { draft.value = "new" })
await tx.isPersisted.promise
console.log('Update successful')
} catch (error) {
console.log('Update failed:', error)
}
// Handle errors
try {
const tx = collection.update("item-1", draft => { draft.value = "new" })
await tx.isPersisted.promise
console.log('Update successful')
} catch (error) {
console.log('Update failed:', error)
}
update<TItem>(
id,
config,
callback): Transaction
update<TItem>(
id,
config,
callback): Transaction
Definiert in: packages/db/src/collection.ts:1744
Aktualisiert ein oder mehrere Elemente in der Collection mithilfe einer Rückruffunktion
• TItem erweitert object = T
unbekannt
(draft) => void
Ein Transaction-Objekt, das die Updateoperation(en) darstellt
Wenn die aktualisierten Daten die Schema-Validierung nicht bestehen
// Update single item by key
const tx = collection.update("todo-1", (draft) => {
draft.completed = true
})
await tx.isPersisted.promise
// Update single item by key
const tx = collection.update("todo-1", (draft) => {
draft.completed = true
})
await tx.isPersisted.promise
// Update multiple items
const tx = collection.update(["todo-1", "todo-2"], (drafts) => {
drafts.forEach(draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Update multiple items
const tx = collection.update(["todo-1", "todo-2"], (drafts) => {
drafts.forEach(draft => { draft.completed = true })
})
await tx.isPersisted.promise
// Update with metadata
const tx = collection.update("todo-1",
{ metadata: { reason: "user update" } },
(draft) => { draft.text = "Updated text" }
)
await tx.isPersisted.promise
// Update with metadata
const tx = collection.update("todo-1",
{ metadata: { reason: "user update" } },
(draft) => { draft.text = "Updated text" }
)
await tx.isPersisted.promise
// Handle errors
try {
const tx = collection.update("item-1", draft => { draft.value = "new" })
await tx.isPersisted.promise
console.log('Update successful')
} catch (error) {
console.log('Update failed:', error)
}
// Handle errors
try {
const tx = collection.update("item-1", draft => { draft.value = "new" })
await tx.isPersisted.promise
console.log('Update successful')
} catch (error) {
console.log('Update failed:', error)
}
values(): IterableIterator<T>
values(): IterableIterator<T>
Definiert in: packages/db/src/collection.ts:1022
Holt alle Werte (virtueller abgeleiteter Zustand)
IterableIterator<T>
Ihre wöchentliche Dosis JavaScript-Nachrichten. Jeden Montag kostenlos an über 100.000 Entwickler geliefert.