Uni Ecto Plugin
Uni can wrap a set of steps in a database transaction. Use the transaction/2 step:
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.
# Create a payment referencing an external Stripe customer
customer_uni = UNI.parse!("uni://customer/stripe/cus_123")
changeset = Payment.changeset(%Payment{}, %
customer_uni: customer_uni,
amount: 49.99
) uni ecto plugin
:ok, payment = Repo.insert(changeset)
If you are searching for "uni ecto plugin," you might actually be looking for a specific adapter. Here is the landscape: Uni can wrap a set of steps in a database transaction
| Library | Strategy | Best For |
| :--- | :--- | :--- |
| Triplex | PostgreSQL Schemas | Most Elixir SaaS apps (Gold standard) |
| Uni Ecto Plugin | Custom (Configurable) | Developers needing fine-grained control |
| Apartment (Rails) | Row-level (Legacy) | Not recommended for Elixir |
| Ash Framework Multi-Tenancy | Resource Layer | Large, complex domain models |
The uni_ecto_plugin sits between Triplex and a manual implementation. It gives you the safety rails of multi-tenancy without locking you into a specific storage strategy. If :decrement fails, :increment never runs, and the
The plugin works with any Ecto repository. You must explicitly tell Uni which repo to use as the default. This can be set in your config/config.exs:
config :uni, default_repo: MyApp.Repo
Alternatively, you can pass the repo as a step option at runtime, but setting a default keeps steps clean.

