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}
No Comments