The Application: Getting Started

Take a look at the basics of the application, what it does, 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.

-module(bookstore_app).
-behaviour(application).

%% Application callbacks
-export([start/2, stop/1]).

start(_StartType, _StartArgs) ->
    bookstore_sup:start_link().

stop(_State) ->
    ok.

And now for the supervisor. Let’s look at how that works.

The supervisor

This is what our supervisor would look like.

-module(bookstore_sup).
-behaviour(supervisor).

-export([start_link/0]).
-export([init/1]).

start_link() ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).

init([]) ->
    bookstore_db:load_queries(),
    {ok, {{one_for_all, 0, 1}, []}}.

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.