The Application: Getting Started
Take a look at the basics of the application and the SQL queries that the application will be using.
We'll cover the following
The application
The application just starts a standard supervisor without children. This is how it’s done.
defmodule Bookstore.App do
use Application
def start(_type, _args) do
Bookstore.Sup.start_link()
end
def stop(_state) do
:ok
end
end
And now for the supervisor. Let’s look at how that works.
The supervisor
This is what our supervisor would look like.
defmodule Bookstore.Sup do
use Supervisor
def start_link() do
Supervisor.start_link(__MODULE__, [], name: __MODULE__)
end
def init([]) do
Bookstore.DB.load_queries()
Supervisor.init([], strategy: :one_for_one)
end
end
Note that Bookstore.DB.load_queries()
gets called. This function is not yet defined. Its role, though, will be to find all the SQL queries within a file we’ll define in priv/queries.sql
, which are labeled by name in the comments.
Queries
Get hands-on with 1400+ tech skills courses.