DEV Community

Cover image for Getting Started on Elixir and Ecto Part 1
Kenzy Limon
Kenzy Limon

Posted on

6

Getting Started on Elixir and Ecto Part 1

_Ecto provides a standardized API and a set of abstractions for talking to all the different kinds of databases that exist. _

In this article series, we’re going to learn some basics about Ecto, such as Creating a Phoenix project, database setup and connection, creating, reading, updating, and destroying records from a PostgreSQL database.

1. Creating a new Project & add dependencies

Let’s get an Elixir application up and running as quickly as possible by running this command.

mix new taskers --sup

We have to install Ecto and Postgrex as dependencies of our application. Ecto uses Postgrex driver to communicate with a PostgreSQL database. To add these dependencies to our application we will follow the steps below.

Add Ecto and Postgrex to our mix.exs file by modifying it and Finalizing the steps by running the following command.

_Check for the latest version

Run this command : mix deps.get

We now need to set up some configuration for Ecto so that we can execute actions on a database from within the application.
Run this command :

mix ecto.gen.repo -r Taskers.Repo

The above command will generate a configuration file required to connect to a database in the config/config.exs.

To allow the Ecto process which receives and executes our application’s queries we need to do a piece of configuration to be able to query data.

Add this to config/config.exs since the generator does not add it:

config :taskers, ecto_repos: [Taskers.Repo]

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay