Connecting to the database

In the introduction, we hinted at how we'll use Ecto to store our application data in a PostgreSQL database. Ecto is able to connect to many databases, but for each database it needs the respective driver to establish the connection, support queries, and so on.

In our case we'll use the postgrex library, which provides the PostgreSQL Elixir driver. But don't think Ecto is tied to PostgreSQL in any way, because Ecto supports other databases like MySQL, DynamoDB, and SQLite, among others.

Let's start by adding the ecto and postgrex libraries to our elixir_drip umbrella app dependencies:

$ cat apps/elixir_drip/mix.exsdefmodule ElixirDrip.Mixfile do  use Mix.Project  defp deps do    [      {:postgrex, "~> 0.13"}, {:ecto, "~> ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.