Ecto usage patterns

Well, to be more precise, here is full example what I need to type every time I launch new session in order to achieve something similar to ActiveRecord

alias App.Repo
alias App.UserContext.User
import Ecto.Query

User |> where(email: "email") |> preload(:posts) |> Repo.one()

and I need to do it every time I want to work with a data. If I want to explore Post I have to write one more alias, every time I start new session.

Compare it to User.find_by(email: "email").posts and it’s just a short example. In real world it quickly adds up.

User.admin.first.posts.active.published.update_all(published: false)

Imagine how much typing required with Ecto. You have to alias: User, UserContext, Post, PostContext. You have to quickly remember context names as well for a schemas.

It requires lots of effort to write something quickly in console.

On the other hand, in a project code it really isn’t an issue, because you can write much faster with code editor and most aliases are already here. Also, you need to write custom queries much less often than when you’re hacking in a console.