I’ve worked through the book and it starts to click in my head. What’s missing for me are examples how to fallback to some lower level stuff like a custom ecto query with fragments. Sometimes some data needs to be fixed in bulk. It can’t be done in a single query, and the easiest way is to use ecto query in a recursive function that updates the data in smaller chunks in the background. It’s pretty simple using pure ecto, but I’m not sure how do do it using ash resources.
The good news is, you can always fall back to writing Ecto queries directly, as Ash resources are built on top of Ecto schemas. I tend to do this if I need to write data migrations - using resource actions there isn’t great because then the migrations need to be kept up to date (otherwise your app won’t compile).
I’ll have a think about this one, see if we can make a mention about it somewhere. Thanks for the feedback!
Also something to keep in mind:
Ash has support for fragments in its expression syntax just like Ecto.
update :something do
change atomic_update(:value, fragment("?..."))
end
Ash has support for bulk updates using Ash.bulk_update
Resource
|> Ash.Query.filter(name == "foo")
|> Ash.bulk_update!(:action, %{a: 10})
and also generic actions.
action :manual_stuff do
argument :foo, :string, allow_nil?: false
run YourActionImplementation
end
Generic actions can do anything internally including recursive calls back to functions in Ash