← All series

Series contents

Log in to track your progress

  1. 1. Ecto Overview: The Repo Episode
  2. 2. Configuring a new project with Ecto Episode
  3. 3. Creating Ecto Migrations Episode
  4. 4. Schema-less Ecto Queries Episode
  5. 5. Our first Ecto schemas Episode
  6. 6. Some useful Ecto functions Episode
  7. 7. Configuring IEx for working with Ecto Episode
  8. 8. Ecto belongs_to and has_many Episode
  9. 9. Ecto many_to_many and joining through Episode
  10. 10. Naming things in an Ecto project Episode
  11. 11. Ecto changesets: change vs cast Episode
  12. 12. Ecto changesets, validations and constraints Episode
  13. 13. Ecto build_assoc and put_assoc Episode

Configuring IEx for working with Ecto

Throughout this series, we've dropped and re-created our database several times. Each time, we've run example_queries.exs in order to seed the database with our sample data.

mix run example_queries.exs

At the top of that file we have import Ecto.Query, along with several helpful aliases. Up to this point, we've just been copying and pasting those lines into IEx each session.

The .iex.exs file

A better way to do this is to create a .iex.exs file. Anytime IEx is started, it will run the .iex.exs file there is one in in the current directory. If not, it will check for one in the home directory and attempt to run ~/.iex.exs.

This file is the perfect place to add any imports or aliases you always want available in interactive sessions. For this project, create a .iex.exs with the following:

import Ecto.Query
import Ecto.Changeset
alias Ecto.Adapters.SQL
alias Linkly.Repo
alias Linkly.{Bookmark, Link, LinkTag, Tag, User}

Open standalone page ↗

No Comments