Elm前置

Erlang 整合 Elixir/Ecto 配置问题

2019-10-24  本文已影响0人  BlindingDark

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

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


上一篇下一篇

猜你喜欢

热点阅读