Starman3787

Starman3787

DBConnection Compilation Error

hey,

i’m new to elixir so am very unfamiliar with how it all works

i am trying to connect to a MariaDB database using the mariaex driver

i’ve added it to the mix.exs file, as shown:

defmodule Backend.MixProject do
  use Mix.Project

  def project do
    [
      app: :backend,
      version: "0.1.0",
      elixir: "~> 1.9",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  def application do
    [
      mod: {Backend.Application, []},
      extra_applications: [:logger, :cowboy, :plug, :poison]
    ]
  end

  defp deps do
    [
      {:plug_cowboy, "~> 1.0.0"},
      {:poison, "~> 3.1"},
      {:mariaex, "~> 0.9.1"}
    ]
  end
end

…and i’ve also run mix deps.get

within the application.ex file (where Backend.Application is defined), i have included the line:

Mariaex.start_link(hostname: "localhost", port: "3307", username: "removed", password: "removed", database: "removed")

which according to the docs, should start a connection to the database

however when running iex -S mix in order to run the program, this compilation error is returned:

== Compilation error in file lib/backend/application.ex ==
** (exit) exited in: GenServer.call(DBConnection.Watcher, {:watch, DBConnection.ConnectionPool.Supervisor, {DBConnection.ConnectionPool.Pool, {#PID<0.190.0>, #Reference<0.1191833633.3142189059.94268>, Mariaex.Protocol, [hostname: "localhost", port: "3307", username: "removed", password: "removed", database: "removed"]}}}, :infinity)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

and i have no clue what to do to fix this, nor can i find any solutions

any pointers or suggestions for what i could do or try would be hugely appreciated

Marked As Solved

josevalim

josevalim

Creator of Elixir

Can you please include the whole application file? You should start the connection to the database inside the start/2 function, typically as part of the supervision tree. Use mix new my_app —sup to have a better idea. Then, in children, you will do something like this:

{Mariaex, name: :my_app, password: …, …}

Also Liked

Starman3787

Starman3787

thanks for the response, this seems to work now:

defmodule Backend.Application do
  @moduledoc false

  use Application

  def start(_type, _args) do

    children = [
      Plug.Adapters.Cowboy.child_spec(scheme: :http, plug: Backend.Router, options: [port: 8085]),
      Mariaex.child_spec(hostname: "localhost", port: "3307", username: "removed", password: "removed", database: "removed")
    ]
    IO.puts("Worker started on port 8085")

    opts = [strategy: :one_for_one, name: Backend.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

i had called the Maria.start_link() function above the line use Application, which in hindsight seems like a very obvious and careless mistake now on my part

i’ve tried to write this in the way you said, i assume this is what you meant by “supervision tree”?

josevalim

josevalim

Creator of Elixir

Yes, that’s the way to go. I think you are only missing the name option, which you will pass as argument to Mariaex.query functions and similar.

Last Post!

josevalim

josevalim

Creator of Elixir

Yes, that’s the way to go. I think you are only missing the name option, which you will pass as argument to Mariaex.query functions and similar.

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement