{"id":13508789,"url":"https://github.com/azranel/ecto_facade","last_synced_at":"2025-08-21T04:31:14.818Z","repository":{"id":57493067,"uuid":"117365507","full_name":"azranel/ecto_facade","owner":"azranel","description":"Separate your read and write operations in replicated database setup","archived":false,"fork":false,"pushed_at":"2024-06-12T23:48:51.000Z","size":29,"stargazers_count":69,"open_issues_count":8,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-16T13:17:28.763Z","etag":null,"topics":[],"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/azranel.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-01-13T17:55:57.000Z","updated_at":"2024-04-07T08:39:40.000Z","dependencies_parsed_at":"2022-08-28T11:51:33.379Z","dependency_job_id":null,"html_url":"https://github.com/azranel/ecto_facade","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/azranel/ecto_facade","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azranel%2Fecto_facade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azranel%2Fecto_facade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azranel%2Fecto_facade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azranel%2Fecto_facade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azranel","download_url":"https://codeload.github.com/azranel/ecto_facade/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azranel%2Fecto_facade/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271425067,"owners_count":24757400,"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-21T02:00:08.990Z","response_time":74,"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":[],"created_at":"2024-08-01T02:00:58.486Z","updated_at":"2025-08-21T04:31:14.536Z","avatar_url":"https://github.com/azranel.png","language":"Elixir","funding_links":[],"categories":["ORM and Datamapping"],"sub_categories":[],"readme":"# EctoFacade\n\nEctoFacade can be used as interface through which you can query multiple repositories.\nMain objective of this is to use separate separate repository for writes and separate repository for reads.\n\nFor example:\n\nLets say you have PostgreSQL database replicated to 4 different slave nodes that should be used for reads only.\nWith this small library you can do that!\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:ecto_facade, \"~\u003e 0.2.0\"}\n  ]\nend\n```\n\n## Usage\n\nHere is example on how to use `EctoFacade` in your application:\n\n```elixir\ndefmodule MyApp.FacadeRepo do\n  use EctoFacade.Repo,\n    master_repo: MyApp.Repo,\n    read_repos: [MyApp.ReadReplicaOne, MyApp.ReadReplicaTwo],\n    algorithm: MyApp.Repo.ReadAlgorithm,\n    fallback_to_master: false\nend\n\nMyApp.FacadeRepo.all(MyApp.SomeSchema) # and other operations that you would normally do with ecto repo\n```\n\nOptions you can pass when `using` `EctoFacade.Repo` are:\n- `master_repo` - this is master repository that will be used for all write operations\n- `read_repos` - this is list of read repositories that will be used for all read operations. Which repository will be used depends on `algorithm`.\n- `algorithm` - this is module that implements behaviour `EctoFacade.Algorithm` and picks read repository for next read operation.\n- `fallback_to_master` - if set to true then read operation that won't work on read repository, will fallback to master repostiory. If set to false, it will throw exception.\n\nPossible algorithms for selecting repository for read operation:\n- `EctoFacade.Algorithms.Random` - selects randomly repository\n- `EctoFacade.Algorithms.Roundrobin` - selects next repository in list till last and then goes again from beginning\n- `EctoFacade.Algorithms.WeightRoundrobin` - selects next repository in list depending on weight. Check module documentation for more info.\n\nor your own that implement behaviour `EctoFacade.Algorithm`.\n\nfor more information please check documentation\n\n### How to write my own algorithm?\n\nThis is pretty straightforward. Here is implementation of `EctoFacade.Algorithms.Random`:\n\n```elixir\ndefmodule EctoFacade.Algorithms.Random do\n  @moduledoc \"\"\"\n  Default algorithm that just returns random read repository\n  \"\"\"\n  @behaviour EctoFacade.Algorithm\n\n  def get_repo(repos) do\n    Enum.random(repos)\n  end\nend\n```\n\n## Usage (testing)\n\nWhen in test just configure you FacadeRepo to use only master repository. This way you won't have issues with separate repositories with Sandbox Ecto adapter.\n\n## Documentation\n\n[Hex.pm](https://hexdocs.pm/ecto_facade)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazranel%2Fecto_facade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazranel%2Fecto_facade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazranel%2Fecto_facade/lists"}