Some useful Ecto functions

Part of the Ecto Beginner series. This goes over a quick recap of what we've covered and teaches more Repo functions we can use to query the DB.

raw SQL

Repo.query

executing a query directly

Repo.all
Repo.one

batch / schema-less actions

Repo.insert_all
Repo.update_all
Repo.delete_all

single queries (with schema, handle auto timestamps)

Repo.insert
Repo.update
Repo.delete

Some other very common queries

Repo.get
Repo.get! (and analogues like insert!, delete!)
Repo.get_by

Repo.aggregate (with :count, :avg, etc)
Repo.exist?

Back to index

No Comments