Composing Ecto Multi Queries

I love Ecto.Multi but there are few rough edges to my understanding…

  1. seems to be the superior option in almost every non-trivial case (i.e. when one operation depends on a previous one in the pipeline). It seems a little awkward, compared to just using a Multi.delete / Multi.update etc.

  2. dynamic operation step naming - I suppose a naive approach suffices, just wondering if anyone has good insight / tips

I found to be vastly more readable as soon as I put all the anonymous functions it uses into real functions instead of inlining them.


Good pt

FWIW, I ended up wrapping each in a function instead, which I really like…

def delete(...), do:
    |> (get_by_multi ...)
    |> (delete_multi ...)
    |> Example.Repo.transaction  
    |> ...
  defp get_by_multi(multi, ....), do:
    |> ( ... )
  defp delete_multi(multi, ...), do:
    |> ( ... )
1 Like