Bulk Delete/Truncate

What is the best way to delete all resources that pass a filter, or in some cases truncate a table to ensure it is empty. This is mostly for admin type functions to reset after some issue with normal operation where the data can be reloaded afterwards.
2 Replies
ZachDaniel
ZachDaniel2y ago
Currently we don't have bulk destroys (but we will). You have two options: 1. roll your own with ecto. Repo.delete_all(from row in Resource, where: ...) ought to work 2. roll your own assisted by ash
Resource
|> Ash.Query.filter(foo == bar)
|> Ash.Query.data_layer_query()
|> case do
{:ok, ecto_query} -> Repo.delete_all(ecto_query)
{:error, error} -> ...
end
Resource
|> Ash.Query.filter(foo == bar)
|> Ash.Query.data_layer_query()
|> case do
{:ok, ecto_query} -> Repo.delete_all(ecto_query)
{:error, error} -> ...
end
TechnoMage
TechnoMageOP2y ago
THanks, I ended up doing 1, but will revise when you have it directly supported.

Did you find this page helpful?