Uni Ecto Plugin
In the world of Elixir development, Ecto is the undisputed king of database wrappers and query generators. It is robust, composable, and deeply integrated into the Phoenix ecosystem. However, as applications grow, developers often find themselves repeating the same boilerplate: setting up Repo.insert , handling changeset errors, managing association preloads, and formatting responses.
def transfer_funds(from_id, to_id, amount) do Uni.new() |> Ecto.transaction(fn -> Uni.new() |> add_step(:decrement, Debit.run(from_id, amount)) |> add_step(:increment, Credit.run(to_id, amount)) |> Uni.execute() end) |> Uni.execute() end If :decrement fails, :increment never runs, and the transaction rolls back. Ecto’s preloading is crucial. Use Ecto.preload/3 as a step: uni ecto plugin
alias Uni.Ecto step = Ecto.get(MyApp.Post, post_id) |> Ecto.preload([:comments, :author]) In the world of Elixir development, Ecto is