MCPcopy Create free account
hub / github.com/TanStack/db / removeIndex

Method removeIndex

packages/db/src/collection/indexes.ts:304–327  ·  view source on GitHub ↗

* Removes an index from this collection. * Returns true when an index existed and was removed, false otherwise.

(indexOrId: BaseIndex<TKey> | number)

Source from the content-addressed store, hash-verified

302 * Returns true when an index existed and was removed, false otherwise.
303 */
304 public removeIndex(indexOrId: BaseIndex<TKey> | number): boolean {
305 this.lifecycle.validateCollectionUsable(`removeIndex`)
306
307 const indexId = typeof indexOrId === `number` ? indexOrId : indexOrId.id
308 const index = this.indexes.get(indexId)
309 if (!index) {
310 return false
311 }
312
313 if (typeof indexOrId !== `number` && index !== indexOrId) {
314 // Passed a different index instance with the same id — do not remove.
315 return false
316 }
317
318 this.indexes.delete(indexId)
319
320 const metadata = this.indexMetadata.get(indexId)
321 this.indexMetadata.delete(indexId)
322 if (metadata) {
323 this.events.emitIndexRemoved(metadata)
324 }
325
326 return true
327 }
328
329 /**
330 * Returns a sorted snapshot of index metadata.

Callers

nothing calls this directly

Calls 4

emitIndexRemovedMethod · 0.80
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected