DB Docs
API Reference
- Core API Reference
- Collection
- createCollection
- liveQueryCollectionOptions
- createLiveQueryCollection
- createOptimisticAction
- createTransaction
- Electric DB Collection
- electricCollectionOptions
- Query DB Collection
- queryCollectionOptions
- RxDB DB Collection
- rxdbCollectionOptions
- PowerSync Collection
- powerSyncCollectionOptions
- createIndexedDB
- indexedDBCollectionOptions
- React Hooks
- useLiveQuery
AI/LLM: This documentation page is available in plain markdown format at/db/latest/docs/reference/functions/getByKey.md
getByKey
ts
function getByKey<T>(objectStore, key): Promise<T | undefined>;Defined in: packages/db/src/indexed-db-wrapper.ts:426
Retrieves a single item by its key from an object store.
Type Parameters#
T#
T
The type of the item
Parameters#
objectStore#
IDBObjectStore
The IDBObjectStore to read from
key#
IDBValidKey
The key of the item to retrieve
Returns#
Promise<T | undefined>
A promise that resolves to the item, or undefined if not found
Example#
ts
await executeTransaction(db, 'todos', 'readonly', async (tx, stores) => {
const todo = await getByKey<Todo>(stores.todos, 1)
if (todo) {
console.log('Found todo:', todo)
}
})