1
我需要config.exs定義多個外生回購多個外生回購,但我不希望由一個定義它們一個:如何界定config.exs
config CC, CC.Repo.S0,
adapter: Ecto.Adapters.Postgres,
hostname: "192.168.0.100",
database: "postgres",
username: "postgres",
password: "12345678"
config CC, CC.Repo.S1,
adapter: Ecto.Adapters.Postgres,
hostname: "192.168.0.101",
database: "postgres",
username: "postgres",
password: "12345678"
...
所以我定義了一個回購列表並嘗試在循環中定義它們:
__repo_all__ = [
[ hostname: "192.168.0.100",
database: "postgres",
username: "postgres",
password: "12345678" ],
[ hostname: "192.168.0.101",
database: "postgres",
username: "postgres",
password: "12345678" ]]
__repo_count__ = Enum.count(__repo_all__)
config CC, :repo_all, __repo_all__
config CC, :repo_count, __repo_count__
Enum.reduce(__repo_all__, 0, fn(opts, n) ->
config CC, String.to_atom(Enum.join([CC.Repo, ".S", n])),
[{:adapter, Ecto.Adapters.Postgres} | opts]
n + 1
end)
我看不到任何回購的配置,同時呼籲Application.get_all_env(CC),但的配置值:repo_all和:repo_count都是可見的。
我該怎麼做才能使它工作?
在此先感謝!
感謝您的回答!我在這裏打開了一個問題:https://github.com/elixir-lang/elixir/issues/3243 – 2015-04-06 01:47:19
上述問題已得到解決。 – rockydgeekgod 2016-11-18 20:51:12