Krug.EnviromentReader (Krug v0.4.14) View Source

Provides a mechanism to simplificate the Ecto db configuration on build time.

Should be used whit a module that implements Krug.EctoEnviromentDecisor behavior and other module that implements Krug.EctoEnviroment behavior.

Utilization Example:

defmodule MyApp.Enviroment.Reader do

  use Krug.EnviromentReader, decisor: MyApp.EnviromentDecisor, enviroment: MyApp.Enviroment

end

After maked this, we could use it to configure a Ecto Repo

defmodule MyApp.App.Repo do

  use Ecto.Repo, otp_app: :ex_app, adapter: Ecto.Adapters.MyXQL
  alias MyApp.Enviroment.Reader
 
  def init(_type, config) do
    config = Keyword.put(config, :hostname,               Reader.read_key_value("APPDB_HOST"))
    config = Keyword.put(config, :port, String.to_integer(Reader.read_key_value("APPDB_PORT")))
    config = Keyword.put(config, :database,               Reader.read_key_value("APPDB_DATABASE"))
    config = Keyword.put(config, :username,               Reader.read_key_value("APPDB_USERNAME"))
    config = Keyword.put(config, :password,               Reader.read_key_value("APPDB_PASSWORD"))
    config = Keyword.put(config, :pool_size, 10)
    config = Keyword.put(config, :timeout, 60_000)
    config = Keyword.put(config, :ownership_timeout, 60_000)
    config = Keyword.put(config, :queue_target, 500)
    config = Keyword.put(config, :queue_interval, 10_000)
    {:ok, config}
  end
 
end