{"id":16656340,"url":"https://github.com/danilamihailov/differ_ecto","last_synced_at":"2026-05-19T21:33:38.574Z","repository":{"id":57490023,"uuid":"237667213","full_name":"DanilaMihailov/differ_ecto","owner":"DanilaMihailov","description":"Ecto.Type for Differ (and some helpers)","archived":false,"fork":false,"pushed_at":"2020-02-14T19:24:25.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T19:50:02.232Z","etag":null,"topics":["diff","differ","elixir","elixir-library"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanilaMihailov.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":"2020-02-01T19:35:02.000Z","updated_at":"2020-05-02T00:40:47.000Z","dependencies_parsed_at":"2022-09-26T18:10:44.559Z","dependency_job_id":null,"html_url":"https://github.com/DanilaMihailov/differ_ecto","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanilaMihailov%2Fdiffer_ecto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanilaMihailov%2Fdiffer_ecto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanilaMihailov%2Fdiffer_ecto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanilaMihailov%2Fdiffer_ecto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanilaMihailov","download_url":"https://codeload.github.com/DanilaMihailov/differ_ecto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243277488,"owners_count":20265350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["diff","differ","elixir","elixir-library"],"created_at":"2024-10-12T09:57:04.761Z","updated_at":"2025-12-26T21:50:41.074Z","avatar_url":"https://github.com/DanilaMihailov.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DifferEcto [![Hex Version](https://img.shields.io/hexpm/v/differ_ecto.svg)](https://hex.pm/packages/differ_ecto) [![docs](https://img.shields.io/badge/docs-hexpm-blue.svg)](https://hexdocs.pm/differ_ecto/) [![Coverage Status](https://coveralls.io/repos/github/DanilaMihailov/differ_ecto/badge.svg?branch=master)](https://coveralls.io/github/DanilaMihailov/differ_ecto?branch=master)\n\n\n`Ecto.Type` for `Differ` (and some helpers)\n\n## Installation\n\nThe package can be installed\nby adding `differ_ecto` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:differ_ecto, \"~\u003e 0.1-pre\"}\n  ]\nend\n```\n\n## Documentation\n\nDocumentation can be found at [https://hexdocs.pm/differ_ecto](https://hexdocs.pm/differ_ecto).\n\n\n## Usage\n\nYou can use json array to store diffs like this\n\n```elixir\ndefmodule Example do\n  use Ecto.Schema\n  # gives us Diffable, Patchable and Diff\n  use DifferEcto\n\n  # we have to skip :diffs field\n  # skip timestamps as well\n  @derive [{Diffable, skip: [:updated_at, :diffs]}, Patchable]\n  schema \"example\" do\n    field :body, :string\n    field :title, :string\n    # we want to store list of diffs in document\n    field :diffs, {:array, Diff}, default: []\n    timestamps()\n  end\nend\n\n```\n\nthen when you do updates, you need to calculate diffs\n\n```elixir\n  def update(%Example{} = ex, attrs) do\n    import Ecto.Changeset\n    ex\n    |\u003e Example.changeset(attrs)\n    |\u003e Repo.update()\n    |\u003e case do\n      # after successful update run diff\n      {:ok, new_ex} -\u003e\n        diff = DifferEcto.diff(ex, new_ex)\n        new_diffs = [diff | List.wrap(ex.diffs)]\n\n        # save diff to list of diffs\n        new_ex \n        |\u003e cast(%{diffs: new_diffs}, [:diffs])\n        |\u003e Repo.update()\n      val -\u003e\n        val\n    end\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilamihailov%2Fdiffer_ecto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanilamihailov%2Fdiffer_ecto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilamihailov%2Fdiffer_ecto/lists"}