Why I’m getting this error when trying to dynamically connect to repo?
insert.ex file
{:ok, _} = Application.ensure_all_started(:req)
ct = %{
chain: "ethereum",
coin: "ETH",
transaction_value: 12.345,
transaction_charged: 1.234,
ref: "test_ref",
payload: "test_payload",
public: "test_public",
private: "test_private",
status: false
}
default_dynamic_repo = MyApp.Repo.get_dynamic_repo()
{:ok, repo} =
MyApp.Repo.start_link(
name: :gatinhos,
hostname: "localhost",
username: "pedri",
password: "1234",
pool_size: 1
)
try do
MyApp.Repo.put_dynamic_repo(repo)
MyApp.Repo.all(Post)
after
MyApp.Repo.put_dynamic_repo(default_dynamic_repo)
Supervisor.stop(repo)
end
application.ex
defmodule TestesPay.Application do
use Application
def start(_type, _args) do
Dotenv.load()
children = [
MyApp.Repo,
]
opts = [strategy: :one_for_one, name: Myapp.Supervisor] # Add a space after name:
Supervisor.start_link(children, opts)
end
end
mix.exs file`defmodule TestesPay.MixProject do
use Mix.Project
def project do
[
app: :testes_pay,
version: "0.1.0",
elixir: "~> 1.16",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :postgrex],
mod: {TestesPay.Application, []}
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:req, "~> 0.5.0"},
{:ecto_sql, "~> 3.6"},
{:postgrex, "~> 0.19.1"},
{:rustler, "~> 0.34.0"},
{:dotenv, "~> 3.0"},
{:decimal, "~> 2.0"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
** (exit) shutdown: failed to start child: DBConnection.ConnectionPool ** (EXIT) exited in: GenServer.call(DBConnection.Watcher, {:watch, DBConnection.ConnectionPool.Supervisor, {DBConnection.ConnectionPool.Pool, {#PID<0.215.0>, #Reference<0.226797208
I dont need to load it dynamic, but I couldnt also connect via the default connection in the Ecto docs via config.,exs
i’m able to give cli commands suach as Ecto migrate etc and it connects to db make changes, but querying it by code isnt working