Definiert in: packages/db/src/collection.ts:77
Erweiterte Collection-Schnittstelle, die sowohl den Datentyp T als auch die Dienstprogramme TUtils enthält
• T extends object = Record<string, unknown>
Der Typ der Elemente in der Collection
• TKey erweitert string | number = string | number
Der Typ des Schlüssels für die Collection
• TUtils erweitert UtilsRecord = {}
Der Dienstprogramm-Datensatztyp
• TSchema extends StandardSchemaV1 = StandardSchemaV1
• TInsertInput extends object = T
Der Typ für Einfügeoperationen (kann sich von T unterscheiden, wenn Schemata Standardwerte haben)
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
CollectionImpl.optimisticDeletes
optimisticUpserts: Map<TKey, T>;
optimisticUpserts: Map<TKey, T>;
Definiert in: packages/db/src/collection.ts:220
CollectionImpl.optimisticUpserts
pendingSyncedTransactions: PendingSyncedTransaction<T>[] = [];
pendingSyncedTransactions: PendingSyncedTransaction<T>[] = [];
Definiert in: packages/db/src/collection.ts:215
CollectionImpl.pendingSyncedTransactions
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
readonly utils: TUtils;
readonly utils: TUtils;
Definiert in: packages/db/src/collection.ts:84
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
Gibt den aktuellen Zustand der Collection als Map zurück
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 Schlüssel Bezeichner sind
get status(): CollectionStatus
get status(): CollectionStatus
Definiert in: packages/db/src/collection.ts:336
Gibt den aktuellen Status der Collection zurück
get toArray(): T[]
get toArray(): T[]
Definiert in: packages/db/src/collection.ts:2071
Gibt den aktuellen Zustand der Collection als Array zurück
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
Alle Einträge abrufen (virtueller abgeleiteter Zustand)
IterableIterator<[TKey, T]>
cleanup(): Promise<void>
cleanup(): Promise<void>
Definiert in: packages/db/src/collection.ts:583
Bereinigt die Collection, indem die Synchronisierung gestoppt und die Daten gelöscht werden. Dies kann manuell oder automatisch durch die 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
CollectionImpl.commitPendingTransactions
createIndex<TResolver>(indexCallback, config): IndexProxy<TKey>
createIndex<TResolver>(indexCallback, config): IndexProxy<TKey>
Definiert in: packages/db/src/collection.ts:1344
Erstellt einen Index in einer Collection für schnellere Abfragen. Indizes verbessern die Abfrageleistung erheblich, indem sie Binärsuchen und Bereichsabfragen anstelle von vollständigen Scans ermöglichen.
• TResolver extends IndexResolver<TKey> = typeof BTreeIndex
Der Typ des Index-Resolvers (Konstruktor oder asynchroner Loader)
(row) => any
Funktion, die den indizierten Wert aus jedem Element extrahiert
IndexOptions<TResolver> = {}
Konfiguration inklusive Index-Typ und typspezifischen Optionen
IndexProxy<TKey>
Ein Index-Proxy, der Zugriff auf den Index bietet, sobald dieser 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')
})
CollectionImpl.currentStateAsChanges
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
Alle Einträge abrufen (virtueller abgeleiteter Zustand)
IterableIterator<[TKey, T]>
forEach(callbackfn): void
forEach(callbackfn): void
Definiert in: packages/db/src/collection.ts:1055
Führt einen Callback 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
CollectionImpl.generateGlobalKey
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 den Schemavalidierung 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 zur Verwendung bereit ist. Gibt true zurück, wenn die Collection von ihrer Synchronisierungsimplementierung 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
Alle Schlüssel abrufen (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 einen Callback, der ausgeführt werden soll, wenn die Collection zum ersten Mal bereit ist. Nützlich zum Vorladen von Collections.
() => void
Funktion, die aufgerufen wird, wenn die Collection zum ersten Mal bereit ist
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
CollectionImpl.onTransactionStateChange
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
Startet die Synchronisierung sofort – interner Aufruf für kompilierte Abfragen. Dies umgeht das Lazy Loading für spezielle Fälle wie Live-Abfrageergebnisse.
void
CollectionImpl.startSyncImmediate
stateWhenReady(): Promise<Map<TKey, T>>
stateWhenReady(): Promise<Map<TKey, T>>
Definiert in: packages/db/src/collection.ts:2052
Gibt den aktuellen Zustand der Collection als Map zurück, löst aber 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, das sich zu einer Map mit allen Elementen in der Collection auflöst
subscribeChanges(callback, options): () => void
subscribeChanges(callback, options): () => void
Definiert in: packages/db/src/collection.ts:2158
Abonniert Änderungen in der Collection
(changes) => void
Funktion, die aufgerufen wird, wenn sich Elemente ändern
SubscribeChangesOptions<T> = {}
Abonnementoptionen einschließlich includeInitialState und Where-Filter
Funktion
Abmeldefunktion – Rufen Sie diese auf, um Änderungen nicht mehr zu verfolgen
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')
})
CollectionImpl.subscribeChanges
subscribeChangesKey(
key,
listener,
__namedParameters): () => void
subscribeChangesKey(
key,
listener,
__namedParameters): () => void
Definiert in: packages/db/src/collection.ts:2197
Abonniert Änderungen für einen bestimmten Schlüssel
TKey
ChangeListener<T, TKey>
boolean = false
Funktion
void
CollectionImpl.subscribeChangesKey
toArrayWhenReady(): Promise<T[]>
toArrayWhenReady(): Promise<T[]>
Definiert in: packages/db/src/collection.ts:2081
Gibt den aktuellen Zustand der Collection als Array zurück, löst aber erst auf, wenn Daten verfügbar sind. Wartet, bis der erste Sync-Commit abgeschlossen ist, bevor er aufgelöst wird.
Promise<T[]>
Promise, das sich zu einem Array mit allen Elementen in der Collection auflöst
CollectionImpl.toArrayWhenReady
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 Callback-Funktion
• TItem extends object = T
unbekannt[]
(drafts) => void
Ein Transaction-Objekt, das die Update-Operation(en) darstellt
Wenn die aktualisierten Daten die Schemavalidierung 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 Callback-Funktion
• TItem extends object = T
unbekannt[]
Einzelner Schlüssel oder Array von Schlüsseln zum Aktualisieren
(drafts) => void
Ein Transaction-Objekt, das die Update-Operation(en) darstellt
Wenn die aktualisierten Daten die Schemavalidierung 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 Callback-Funktion
• TItem extends object = T
unbekannt
(draft) => void
Ein Transaction-Objekt, das die Update-Operation(en) darstellt
Wenn die aktualisierten Daten die Schemavalidierung 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 Callback-Funktion
• TItem extends object = T
unbekannt
(draft) => void
Ein Transaction-Objekt, das die Update-Operation(en) darstellt
Wenn die aktualisierten Daten die Schemavalidierung 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
Ruft alle Werte ab (virtueller abgeleiteter Zustand)
IterableIterator<T>
Ihre wöchentliche Dosis JavaScript-Nachrichten. Jeden Montag kostenlos an über 100.000 Entwickler geliefert.