Following the exercises from Designing Elixir Systems with OTP.
Some additions beyond the book material:
- extra unit tests, mostly showcasing Elixir's features, or expanding on concepts I found unfamiliar
- dialyzer and excoveralls tasks added (
mix dialyzer
andmix coveralls.html
to invoke) - run
iex --dot-iex lib/mastery/examples/api_run.exs -S mix
in the project root to play with the raw API - finished Chapter 7 now :)
- now integratedd
mastery_persistence
intomastery
-
Spin up a local Postgres instance through Docker:
docker run -itd -e POSTGRES_USER=ectotest -e POSTGRES_PASSWORD=ectotest -p 5432:5432 --name postgresql postgres
-
Build both
mastery
andmastery_persistence
(cd
into folder,mix deps.get
,mix compile
) -
cd mastery_persistence && mix ecto.create && mix ecto.migrate
-
cd mastery
and run iex:iex -S mix
-
Run this in the shell:
> MasteryPersistence.record_response(%{ quiz_title: "lol", template_name: "foo", to: "who dis?", email: "lol@email.com", answer: "interrupting cow", correct: true, timestamp: ~U[2019-10-31 19:59:03Z] })
-
Open a new terminal, run
docker exec -it postgresql /bin/bash
-
In the terminal (on the PGSQL container), run
psql --username=ectotest
followed by\c mastery_dev
-
Results:
mastery_dev=# select * from responses; id | quiz_title | template_name | to | email | answer | correct | inserted_at | updated_at ---+------------+---------------+----------+---------------+------------------+---------+---------------------+--------------------- 1 | lol | foo | who dis? | lol@email.com | interrupting cow | t | 2019-10-31 19:59:03 | 2019-10-31 19:59:03 (1 row)