本页还没有译文
本页 22 段还没译成Русский,下面显示的是英文原文。put
还没翻译译自英文(tanstack.com)本页 22 段都还没译
function put<T>(
objectStore,
value,
key?): Promise<IDBValidKey>;Defined in: packages/db/src/indexed-db-wrapper.ts:470
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.
Type Parameters
T
T
The type of the item
Parameters
objectStore
IDBObjectStore
The IDBObjectStore to write to
value
T
The item to write
key?
IDBValidKey
Optional key for the item. Required if the object store doesn't have a keyPath.
Returns
Promise<IDBValidKey>
A promise that resolves to the key of the written item
Example
// 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)
})AI 翻译查看英文原文