Mutations for one-to-many db schema
Hi, I’m wondering if it’s possible to handle mutations outside of the collection but sync after the network call. I’m ok with sacrificing optimistic mutations for simplicity and reduced network calls.
4 Replies
wise-white•2mo ago
not sure what your goal is here — why is this simpler or how would this reduce network calls?
rising-crimsonOP•2mo ago
I have a table called “knowledge_items” that has a ElectricSQL collection. A knowledge item can have one to many “knowledge_item_files” and one to many “knowledge_item_tags”.
I have a form to create/update knowledge items. Inside this form, I have a field for files and a field for tags. When I submit this form, I would like to make one network call to insert the knowledge item, all the files and all the tags.
Because my knowledge item collection schema is the select schema of the “knowledge_items” table I don’t have type inference on files or tags. This results in 3 collections needing to handle their own mutations.
I’m wondering if I’m able to use the knowledge items collection for reads but mutate with a mutation that isn’t constrained to the “knowledge_items” schema? This would mean I lose out on optimistic mutations but would I still achieve the sync?
wise-white•2mo ago
you probably want an action then https://tanstack.com/db/latest/docs/guides/mutations#creating-custom-actions
Mutations | TanStack DB Docs
TanStack DB Mutations TanStack DB provides a powerful mutation system that enables optimistic updates with automatic state management. This system is built around a pattern of optimistic mutation → ba...
rising-crimsonOP•2mo ago
I will have a read - thanks!
Thanks, this solved my problem nicely