Erlang 整合 Elixir/Ecto 配置问题

erlang rebar3_elixir_compile elixir ecto


使用 rebar3_elixir_compile 可以方便的将 Elixir 项目集成到 Erlang 项目中。

在使用的过程中发现 Ecto 不能正确读取配置文件。
解决办法,在编译时将 Ecto 配置写入 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

其它读取配置文件的问题也可以如法炮制。


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容