Store Operations
CRUD operations available on every store: add, put, get, getAll, delete, clear, count.
Overview
Every store in a svelte-idb database implements the IStore<T> interface, providing a complete set of CRUD operations. All operations return Promises and are fully type-safe.
Caveat: Saving Reactive State
IndexedDB relies on the structured clone algorithm. Svelte 5 reactive proxies cannot be cloned directly and will throw an IDBDataCloneError. Always snapshot your reactive state before saving it to the database.
add(value)
Insert a new record. Throws IDBConstraintError if the key already exists.
put(value)
Insert or update a record. If a record with the same key exists, it is replaced.
get(key)
Retrieve a single record by its primary key. Returns undefined if not found.
getAll()
Retrieve all records from the store.
getAllFromIndex(indexName, query?, count?)
Query records using a secondary index.
delete(key)
Remove a single record by its primary key.
clear()
Remove all records from the store.
count()
Get the number of records in the store.
API Reference
| Name | Type | Description |
|---|---|---|
add(value) | Promise<IDBValidKey> | Insert a new record, returns the generated key |
put(value) | Promise<IDBValidKey> | Insert or replace a record |
get(key) | Promise<T | undefined> | Retrieve a record by primary key |
getAll() | Promise<T[]> | Retrieve all records |
getAllFromIndex() | Promise<T[]> | Query records via a secondary index |
where(indexName) | IQueryBuilder<T> | Create a chainable index query builder |
delete(key) | Promise<void> | Remove a record by key |
clear() | Promise<void> | Remove all records |
count() | Promise<number> | Count total records |