Closed ChocolateLoverRaj closed 2 years ago
The 4th argument of the upgrade callback is the transaction you're looking for - https://github.com/jakearchibald/idb#opendb
const db = await openDB(name, version, {
upgrade(db, oldVersion, newVersion, transaction) {
// transaction is what you want
},
});
@jakearchibald sorry didn't realize there was a parameter for it
Is your feature request related to a problem? Please describe. I'm trying to modify an existing store in the upgrade function, but if I do
db.transaction()
I get an error saying that I can't do a transaction while the db is being upgraded. I saw this article which usedevt.currentTarget.transaction
, which seems to be an existing transaction for upgrading the db. However, the upgrade function doesn't get the event or the current target in its parameters, so there's currently no way to get data from the db during an upgrade.Describe the solution you'd like
Preferred solution (has breaking change)
Another solution (no breaking changes)