function put<T>(
objectStore,
value,
key?): Promise<IDBValidKey>;Defined in: packages/indexeddb-db-collection/src/wrapper.ts:429
Writes an item to an object store using upsert semantics.
If an item with the same key exists, it will be replaced. If no item with the key exists, a new one will be created.
T
The type of the item
IDBObjectStore
The IDBObjectStore to write to
T
The item to write
IDBValidKey
Optional key for the item. Required if the object store doesn't have a keyPath.
Promise<IDBValidKey>
A promise that resolves to the key of the written item
// With keyPath (key extracted from value)
await executeTransaction(db, 'todos', 'readwrite', async (tx, stores) => {
const key = await put(stores.todos, { id: 1, text: 'Buy milk' })
console.log('Wrote item with key:', key)
})
// Without keyPath (explicit key)
await executeTransaction(db, 'items', 'readwrite', async (tx, stores) => {
const key = await put(stores.items, { text: 'Some data' }, 'myKey')
console.log('Wrote item with key:', key)
})