dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.06k stars 631 forks source link

dexie-cloud feature request: Transaction support on REST API #2003

Open dusty-phillips opened 1 month ago

dusty-phillips commented 1 month ago

alternative title: "OMG What is Dusty Abusing Now?"

I have a situation where I want to change two tables via the REST API and I want those changes to fail or succeed atomically.

Context: I currently store the total number of words in a scene for each day that the user edits the scene. This allows me to calculate "how much have I written each day" queries. This table is getting kind of obnoxious, even on a per-user basis, since there are m*n entries. My plan is to aggregate these into a "how many words were added in total on this day" table and delete historical entries as they age out. I obviously don't want the deletions of aggregated items to be committed until the aggregated object is saved or vice versa.

Some brainstorming:

The second option seems like the most promising. I tried the import endpoint with some semi-valid data and it does seem to reject everything if it can't import one thing. But when creating items, it doesn't auto-generate ids.

dfahlander commented 1 month ago

The sync endpoint has it but it's still a bit verbose to use and no docs of it. Might add some lighter version of it maybe.

dusty-phillips commented 1 month ago

That would be awesome. I've got something working with /import now, but that's not in a db transaction? At least import I can be sure the entire HTTP bundle made it to dexie cloud before it starts making changes, which even if it is not guaranteed, is safer than two separate requests that could fail basically any time a random router decides it is due a vacation.

dfahlander commented 1 month ago

Good you found a way to use import - yes import is much less likely to fail half ways than using the REST API.