Open History to see the last commit
1---
2id: getByKey
3title: getByKey
4---
5
6```ts
7function getByKey<T>(objectStore, key): Promise<T | undefined>;
8```
9
10Defined in: packages/db/src/indexed-db-wrapper.ts:391
11
12Retrieves a single item by its key from an object store.
13
14## Type Parameters
15
16### T
17
18`T`
19
20The type of the item
21
22## Parameters
23
24### objectStore
25
26`IDBObjectStore`
27
28The IDBObjectStore to read from
29
30### key
31
32`IDBValidKey`
33
34The key of the item to retrieve
35
36## Returns
37
38`Promise`\<`T` \| `undefined`\>
39
40A promise that resolves to the item, or undefined if not found
41
42## Example
43
44```typescript
45await executeTransaction(db, 'todos', 'readonly', async (tx, stores) => {
46 const todo = await getByKey<Todo>(stores.todos, 1)
47 if (todo) {
48 console.log('Found todo:', todo)
49 }
50})
51```