Multi-store transaction
retorquere opened this issue · 5 comments
It doesn't look to be possible to create multi-store transactions. query
opens a transaction on all stores when called without an argument, but fails on line 32, as objectStore
doesn't accept an array argument.
I updated the description for query
since it was not meant to be used with an Array of object store names.
Multiple requests across multiple object stores within a single transaction would be required only to call abort
appropriately, but transactions are not exposed, so abort
cannot be called when using query
.
I have to implement a new method for this use case that doesn't involve a callback hell as in vanilla IndexedDB. I will try to figure something out soon.
Multiple requests across multiple object stores within a single transaction would be required only to call
abort
I don't understand? IndexedDB allows opening a single transaction over two stores, update both, and then have the transaction commit, it's just that in the previous implementation of AsyncIndexedDB
it was not possible. Why would you call abort
in this scenario?
I'm trying a few implementations of IndexedDB promise-wrappers but I'm currently leaning towards my my own -- the space doesn't seem to have settled enough to have yielded a few that have wide usage (== battle-tested) except dexie, which is pretty large for what I want, and doesn't have async iterators. If you're actively using this lib I'm open to collaborating on it.
The current implementation leverages the fact that you almost never need to explicitly call commit
because a transaction automatically commits when the last request ends successfully. Having multiple requests in a single transaction is useful for scoping a transaction for rollback in case of a request failure or an explicit abort
, but it shouldn't matter in other cases.
I am currently not using this lib because my job doesn't require me to work with IndexedDB anymore, and the job takes up almost all my time. I won't be able to work on it to expand it for the next month. But your gist looks promising though.
I don't intend to call commit -- hence the
have the transaction commit
as the transaction will automatically commit at the end of the microtask. But that still leaves the fact that multiple stores can be touched within a single all-or-nothing transaction.