_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]
Top comments (0)