{"id":21313747,"url":"https://github.com/carakan/soft_repo","last_synced_at":"2025-08-11T09:16:52.965Z","repository":{"id":57550446,"uuid":"148079229","full_name":"carakan/soft_repo","owner":"carakan","description":"ecto repo wrapper that support soft delete record's","archived":false,"fork":false,"pushed_at":"2018-10-15T04:59:25.000Z","size":62,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T21:16:53.322Z","etag":null,"topics":["ecto","elixir","soft-delete"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/carakan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-09-10T00:47:26.000Z","updated_at":"2018-12-25T11:52:52.000Z","dependencies_parsed_at":"2022-08-29T20:41:24.363Z","dependency_job_id":null,"html_url":"https://github.com/carakan/soft_repo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/carakan/soft_repo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carakan%2Fsoft_repo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carakan%2Fsoft_repo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carakan%2Fsoft_repo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carakan%2Fsoft_repo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carakan","download_url":"https://codeload.github.com/carakan/soft_repo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carakan%2Fsoft_repo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269857731,"owners_count":24486396,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ecto","elixir","soft-delete"],"created_at":"2024-11-21T18:08:31.748Z","updated_at":"2025-08-11T09:16:52.898Z","avatar_url":"https://github.com/carakan.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/carakan/soft_repo.svg?branch=master)](https://travis-ci.org/carakan/soft_repo)\n[![Hex.pm](https://img.shields.io/hexpm/dt/soft_repo.svg)](https://hex.pm/packages/soft_repo)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n# SoftRepo\n\nSimple implementation of soft delete using repository pattern (Ecto Repo).\n\n## Installation\n\n- this package can be installed by adding `soft_repo` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:soft_repo, \"~\u003e 0.2.0\"}\n  ]\nend\n```\n\n- Configure `soft_repo` to use your application repo in `config/config.exs`:\n\n```elixir\nconfig :soft_repo, repo: YourApplicationName.Repo\n```\n\n- **Migrations** for schemas to add support for soft deletion, add soft_repo_column() when creating/modifing a table\n\n```elixir\n  defmodule MyApp.Repo.Migrations.CreateWhatever do\n    use Ecto.Migration\n\n    def change do\n      create table(:whatever) do\n        add(:my_field, :string)\n        add(:my_other_field, :string)\n        timestamps()\n        SoftRepo.Migration.soft_repo_column()\n      end\n    end\n  end\n```\n\n- **Schema**\n\nImport `SoftRepo.Schema` into your module, then add `soft_repo_schema()` to your schema block:\n\n```elixir\n  defmodule Whatever do\n    use Ecto.Schema\n    import SoftRepo.Schema\n\n    schema \"users\" do\n      field(:email, :string)\n      soft_repo_schema()\n    end\n  end\n```\n\n- **Queries** Now you can call `SoftRepo` gobally or alias to your `Repo`\n\n```elixir\nSoftRepo.get(MyApp.User, 1) # will return nil if record is in soft delete state\nSoftRepo.get(MyApp.User, 1, with_thrash: true) # will return the soft deleted record\nSoftRepo.all(MyApp.User) # will exclude soft deleted records\nSoftRepo.all(MyApp.User, with_thrash: true) # will include soft deleted records\nSoftRepo.delete(user) # will update the deleted_at column\nSoftRepo.delete(user, force: true) # will permanently delete the record\nSoftRepo.delete_all(MyApp.User) # will updated the deleted_at columns\nSoftRepo.delete_all(MyApp.User, force: true) # will permanently delete all records\nSoftRepo.restore(MyApp.User, 1) # will restore back the soft deleted record\n```\n\n- **Pagination**, to do pagination (using scrivener) I added a function to use in your `Repo` injected pagination:\n\n```elixir\nSoftRepo.paginate(MyApp.User) # will exclude soft deleted records paginated\n```\n\n## Inspiration\n\n- [Gist](https://gist.github.com/ahmadshah/83a695ac66d98a833d6d576815e6931d)\n- [ecto_soft_delete](https://github.com/revelrylabs/ecto_soft_delete)\n\n## TODO's\n\n- [ ] Use Metaprogramming to change from set config Repo to inject into a module.\n- [ ] Support associations, like `has_many(:whatevers, on_delete: :soft_delete)`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarakan%2Fsoft_repo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarakan%2Fsoft_repo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarakan%2Fsoft_repo/lists"}