jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.29k stars 353 forks source link

IDBPDatabase.transaction typing should allow the `durability` parameter #203

Closed xiaoxingwa closed 3 years ago

xiaoxingwa commented 3 years ago

IDBDatabase.transaction has a 3rd parameter "options" on Chrome which includes a durability setting for the transaction. See https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/transaction and https://www.chromestatus.com/feature/5730701489995776

IDBPDatabase.transaction should allow this parameter.

jakearchibald commented 3 years ago

This works today, but the typescript defs need updating.

tony-scio commented 3 years ago

Would be really handy if there were a way to use the convenience methods with durability: 'relaxed'. Either allowing the param to be passed to them or allowing it to be set once in openDB or similar.

jakearchibald commented 3 years ago

Yeah, that seems fair

jakearchibald commented 3 years ago

Actually, I'm going to hold off on this.

Right now the shortcut methods are all .methodName(store, ...paramsForMethod), and it isn't clear where transaction options fit in with that. If we get more transaction options, I'll take another look at this.

tony-scio commented 3 years ago

Thanks so much for the quick response. That's fair.

Btw, for your consideration, it's possible that it'd be a good idea for idb to unconditionally set durability: relaxed. It's the default in Firefox, but not chrome for conservative historical reasons. It's likely that it will (or should) become the default in chrome.

More background is below, but the tldr is that it's a huge perf win and the data loss only happens in catastrophic failures like OS crash or power failure (tab closing, browsing closing and chrome crashing are all safe).

https://www.chromestatus.com/feature/5730701489995776

jakearchibald commented 3 years ago

Hmm you make a good case, but I don't want this library to diverge too much from default IDB behaviour. The thing that keeps this library small is it's just a small proxy over the top of the existing API.

I liked your idea of specifying the transaction durability type during the opening of the database. I wonder if the IDB standards folks have considered that as a path forward.

tony-scio commented 3 years ago

It's all good :-) Only a couple of extra lines on my end to get behavior I wanted here. Thanks for the excellent library, I love the ergonomics.