{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/1003","labels_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1003/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1003/comments","events_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1003/events","html_url":"https://github.com/elixir-lang/ecto/issues/1003","id":110699536,"number":1003,"title":"Provide Ecto.Repo.prepare/2","user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elixir-lang/ecto/labels/Kind:Feature","name":"Kind:Feature","color":"009800"},{"url":"https://api.github.com/repos/elixir-lang/ecto/labels/Level:Intermediate","name":"Level:Intermediate","color":"fad8c7"},{"url":"https://api.github.com/repos/elixir-lang/ecto/labels/Note:Discussion","name":"Note:Discussion","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-10-09T17:05:07Z","updated_at":"2015-10-15T19:07:08Z","closed_at":null,"body":"It will be called with query + options, allowing developers to customize queries before they are sent to the repository. For example, one can use this for setting up a query prefix based on some configuration, before reaching the database.\r\n\r\n@Dania02525 and @reset would this be useful in your experience with prefixes? /cc @Tica2 "},"comment":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/comments/148490614","html_url":"https://github.com/elixir-lang/ecto/issues/1003#issuecomment-148490614","issue_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1003","id":148490614,"user":{"login":"Tica2","id":817517,"avatar_url":"https://avatars.githubusercontent.com/u/817517?v=3","gravatar_id":"","url":"https://api.github.com/users/Tica2","html_url":"https://github.com/Tica2","followers_url":"https://api.github.com/users/Tica2/followers","following_url":"https://api.github.com/users/Tica2/following{/other_user}","gists_url":"https://api.github.com/users/Tica2/gists{/gist_id}","starred_url":"https://api.github.com/users/Tica2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tica2/subscriptions","organizations_url":"https://api.github.com/users/Tica2/orgs","repos_url":"https://api.github.com/users/Tica2/repos","events_url":"https://api.github.com/users/Tica2/events{/privacy}","received_events_url":"https://api.github.com/users/Tica2/received_events","type":"User","site_admin":false},"created_at":"2015-10-15T19:07:08Z","updated_at":"2015-10-15T19:07:08Z","body":"@josevalim In your next example what is `opts` ? \r\n\r\nwe have a lot of functions: Repo.all/2 Repo.one/2 ...\r\n\r\nI think, with example with process state we don't need opts. \r\n\r\n```elixir\r\n# Based on domain/prefix/user find tenant\r\nMultitenancy.set_current(tenant)\r\n\r\ndefmodule MyRepo do\r\n  use Ecto.Repo\r\n\r\n  def prepare(query, opts) do\r\n    query \r\n     |> Ecto.Queryable.to_query\r\n     |> build_prefix(Multitenancy.get_current)\r\n  end\r\nend\r\n```\r\n\r\n@josevalim for me **PERFECT**"}}