Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dusty-phillips opened this issue May 31, 2024 · 3 comments
Open

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

dusty-phillips opened this issue May 31, 2024 · 3 comments

Comments

@dusty-phillips
Copy link
Contributor

dusty-phillips commented May 31, 2024

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:

  • dexie-cloud gets some kind of startTransaction and commit REST endpoints and if you call any queries in between you need to pass the transaction id with it. (No idea how well that would cooperate with the existing server implementation)
  • dexie-cloud has a single "transaction" endpoint that you can pass multiple JSON bodies into. Possibly the undocumented /import endpoint already does this? (Oh please let this be a already-solved problem 🙏🏻)
  • Some kind of server-side indexedDB (e.g fakeIndexedDB) could immitate each user and use the client API to do syncs correctly with all dexie-cloud's existing CRDT goodness.
  • hijack the undocumented /sync endpoint to send the same kind of data that the browser sends (there is no way this ends well)

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
Copy link
Collaborator

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
Copy link
Contributor Author

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants