{"id":32163956,"url":"https://github.com/feymartynov/ex_operation","last_synced_at":"2026-02-23T04:34:07.310Z","repository":{"id":62429221,"uuid":"139373598","full_name":"feymartynov/ex_operation","owner":"feymartynov","description":"A library for making domain operations in Elixir","archived":false,"fork":false,"pushed_at":"2019-06-22T02:20:26.000Z","size":47,"stargazers_count":35,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-14T18:44:37.993Z","etag":null,"topics":["business-logic","ecto","elixir","railway-oriented-programming","transaction"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feymartynov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-02T00:47:57.000Z","updated_at":"2024-05-18T05:40:29.000Z","dependencies_parsed_at":"2022-11-01T20:02:20.730Z","dependency_job_id":null,"html_url":"https://github.com/feymartynov/ex_operation","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/feymartynov/ex_operation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feymartynov%2Fex_operation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feymartynov%2Fex_operation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feymartynov%2Fex_operation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feymartynov%2Fex_operation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feymartynov","download_url":"https://codeload.github.com/feymartynov/ex_operation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feymartynov%2Fex_operation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29738079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T02:24:00.660Z","status":"ssl_error","status_checked_at":"2026-02-23T02:22:56.087Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["business-logic","ecto","elixir","railway-oriented-programming","transaction"],"created_at":"2025-10-21T14:41:12.424Z","updated_at":"2026-02-23T04:34:07.299Z","avatar_url":"https://github.com/feymartynov.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExOperation\n\n[![Build Status](https://travis-ci.org/feymartynov/ex_operation.svg?branch=master)](https://travis-ci.org/feymartynov/ex_operation)\n\nA library for making domain operations wrapped in a single database transaction.\n\n## Resources\n\n* [Documentation](https://hexdocs.pm/ex_operation)\n* [Hex package](https://hex.pm/packages/ex_operation)\n* [ExOperation: organizing business logic with operations in Elixir](https://medium.com/@feymartynov/exoperation-organizing-business-logic-with-operations-in-elixir-ce28a5f8b5ef)\n* [Talk about ExOperation at Elixir-Lang Moscow meetup](https://youtu.be/ZIib_TV1tmo?t=2360) (in Russian)\n* [Example Phoenix app](https://github.com/feymartynov/ex_operation_phoenix_example)\n\n## Example\n\nAn operation definition:\n\n```elixir\ndefmodule MyApp.Book.Update do\n  use ExOperation, params: %{\n    id!: :integer,\n    title!: :string,\n    author_id: :integer\n  }\n\n  def validate_params(changeset) do\n    changeset\n    |\u003e Ecto.Changeset.validate_length(:title, min: 5)\n  end\n\n  def call(operation) do\n    operation\n    |\u003e find(:book, schema: MyApp.Book, preload: [:author])\n    |\u003e find(:author, schema: MyApp.Author, id_path: [:author_id], optional: true)\n    |\u003e step(:result, \u0026do_update(operation.context, \u00261, operation.params))\n    |\u003e after_commit(\u0026send_notifcation(\u00261))\n  end\n\n  defp do_update(context, txn, params) do\n    txn.book\n    |\u003e Ecto.Changeset.cast(params, [:title])\n    |\u003e Ecto.Changeset.put_assoc(:author, txn.author)\n    |\u003e Ecto.Changeset.put_assoc(:updated_by, context.current_user)\n    |\u003e MyApp.Repo.update()\n  end\n\n  defp send_notification(txn) do\n    # …\n    {:ok, txn}\n  end\nend\n```\n\nThe call:\n\n```elixir\ncontext = %{current_user: current_user}\n\nwith {:ok, %{result: book}} \u003c- MyApp.Book.Update |\u003e ExOperation.run(context, params) do\n  # …\nend\n```\n\n### Usage with Phoenix\n\nAn example Phoenix app can be found here: [ex_operation_phoenix_example](https://github.com/feymartynov/ex_operation_phoenix_example).\n\n## Features\n\n* [Railway oriented](https://fsharpforfunandprofit.com/rop/) domain logic pipeline.\n* Running all steps in a single database transaction. It uses [Ecto.Multi](https://hexdocs.pm/ecto/Ecto.Multi.html) inside.\n* Params casting \u0026 validation with `Ecto.Changeset`. Thanks to [params](https://github.com/vic/params) library.\n* Convenient fetching of entitites from the database.\n* Context passing. Useful for passing current user, current locale etc.\n* Composable operations: one operation can call another through `suboperation/3` function.\n* Changing operation scenario based on previous steps results with `defer/2`.\n* Hooks: `before_transaction/1`, `after_commit/1`.\n\n## Installation\n\nAdd the following to your `mix.exs` and then run `mix deps.get`:\n\n```elixir\ndef deps do\n  [\n    {:ex_operation, \"~\u003e 0.5.0\"}\n  ]\nend\n```\n\nAdd to your `config/config.exs`:\n\n```elixir\nconfig :ex_operation,\n  repo: MyApp.Repo\n```\n\nwhere `MyApp.Repo` is the name of your Ecto.Repo module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeymartynov%2Fex_operation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeymartynov%2Fex_operation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeymartynov%2Fex_operation/lists"}