Ecto.Multi like transactions

Hi Ash community, I'm looking to find some examples around how to bundle together database operations into one transaction. Like in Ecto.Multi. In practice I would like to do something like create or update operation where entry's existence is being checked before creation. In one transaction. Can you please point me to the relevant doc resource or show me an example of something similar? Thank you in advance!
4 Replies
ZachDaniel
ZachDanielβ€’2y ago
You have a few options πŸ™‚ 1. Ash.Flow has a transaction step type 2. you can add before and after action hooks to an action and those happen in the same transaction. 3. The operation you’re talking about sounds like it might be an upsert (create or update) which is supported as an option when creating.
Musashi 🌊
Musashi 🌊OPβ€’2y ago
Thank you Zach, I'll look into these.
ZachDaniel
ZachDanielβ€’2y ago
You can also use ecto.multi with ash if you want
Musashi 🌊
Musashi 🌊OPβ€’2y ago
Thanks for noting. I want to try out the Ash ways first :). I found ash_hq repo has some good examples of flow compositions. I put a link here. Maybe someone else will also be looking for information about this. https://github.com/ash-project/ash_hq/blob/3832da271add361eb56debca16e628b013954ee2/lib/ash_hq/docs/flows/search/search.ex#L18
GitHub
ash_hq/lib/ash_hq/docs/flows/search/search.ex at 3832da271add361eb5...
The Ash Framework homepage and documentation site. - ash_hq/lib/ash_hq/docs/flows/search/search.ex at 3832da271add361eb56debca16e628b013954ee2 Β· ash-project/ash_hq

Did you find this page helpful?