The provides a set of pre-built, reusable steps specifically for database operations. Instead of writing Repo.insert(user_changeset) wrapped in a custom function, you call Uni.Ecto.insert() as a step in your pipeline. Part 2: Why Use the Uni Ecto Plugin? You might ask: "Why not just use Ecto directly?" Problem 1: Repo Hardcoding Every module that needs a database operation must know which Repo module to call. This makes testing harder (you have to use Mox or swap configs) and reduces portability. Problem 2: Error Inconsistency Ecto returns :error, changeset . But what about validation errors vs. database constraint errors vs. connection errors? Uni normalizes all Ecto errors into a standard Uni.Error.t() structure. Problem 3: Composition Trying to compose Repo.transaction/1 with other side effects (HTTP calls, file writes) is error-prone. Uni’s Step system handles transactions declaratively. Problem 4: Visibility Uni includes telemetry and detailed step-by-step tracing. With raw Ecto, you lose granular context about which step of a business process failed.
# test_helper.exs Uni.Ecto.Test.start(repo: MyApp.Repo, mode: :no_db) Now Ecto.get/3 returns a predefined fixture. This enables lightning-fast unit tests. | Feature | Raw Ecto | With Contexts (no Uni) | Uni + Ecto Plugin | |---------|----------|------------------------|--------------------| | Error tracking | :error, term | :error, term | Structured Uni.Error , step name included | | Transactions | Manual Repo.transaction/1 | Nested callbacks | Declarative Ecto.transaction/2 | | Side effects | Interleaved | Mixed in functions | Separate steps, auto-halt on error | | Testability | Mox or sandbox | Partial mocks | Per-step stubs + telemetry | | Readability | with chains | Varies | Linear pipeline with named steps | Part 9: Real-World Example – Blog Post with Tags Let’s finish with a non-trivial example: creating a blog post with tags, ensuring tags are upserted (find or create), and linking. uni ecto plugin
The Uni Ecto Plugin transforms your data layer into a set of . Part 3: Installation & Basic Setup Let’s get our hands dirty. Add the necessary dependencies to your mix.exs : The provides a set of pre-built, reusable steps