Core API

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.

add(value)

Insert a new record. Throws IDBConstraintError if the key already exists.

add.ts

put(value)

Insert or update a record. If a record with the same key exists, it is replaced.

put.ts

get(key)

Retrieve a single record by its primary key. Returns undefined if not found.

get.ts

getAll()

Retrieve all records from the store.

getAll.ts

getAllFromIndex(indexName, query?, count?)

Query records using a secondary index.

getAllFromIndex.ts

delete(key)

Remove a single record by its primary key.

delete.ts

clear()

Remove all records from the store.

clear.ts

count()

Get the number of records in the store.

count.ts

API Reference

NameTypeDescription
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
delete(key) Promise<void>Remove a record by key
clear() Promise<void>Remove all records
count() Promise<number>Count total records