erlang rebar3_elixir_compile elixir ecto
使用 rebar3_elixir_compile 可以方便的將 Elixir 項(xiàng)目集成到 Erlang 項(xiàng)目中。
在使用的過(guò)程中發(fā)現(xiàn) Ecto 不能正確讀取配置文件。
解決辦法,在編譯時(shí)將 Ecto 配置寫(xiě)入 application 文件中:
defmodule Your.Application do
@moduledoc """
Your Application
"""
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
use Application
@repos Application.get_env(:your_application, :ecto_repos)
@repo_config Enum.map(
@repos,
fn repo ->
{repo, Application.get_env(:your_application, repo)}
end
)
def start(_type, _args) do
# List all child processes to be supervised
children =
@repo_config ++
[
{Redix, name: :redix}
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Your.Supervisor]
Supervisor.start_link(children, opts)
end
end
其它讀取配置文件的問(wèn)題也可以如法炮制。