...

/

Add Imports and Aliases

Add Imports and Aliases

Learn how to add imports and aliases in IEx.

Add aliases

One of the most valuable things we can do is add aliases for the modules we work with often. We’ll most likely want to start with Repo and most (if not all) of our schema modules. For the MusicDB application, we might do the following:

alias MusicDB.{
Repo,
Artist,
Album,
Track,
Genre,
Log
}

This one addition means that instead of typing this:

album = MusicDB.Repo.get(MusicDB.Album, 1) |> MusicDB.Repo.preload(:tracks)

We can type this:

album = Repo.get(Album, 1) |> Repo.preload(:tracks)

Those saved keystrokes start to add up after a while. ...