Getting the first record
User.first
Repo.one(from x in Model, order_by: [asc: x.id], limit: 1)
# You can hide the order_by since it is ascending by default
Repo.one(from x in Model, limit: 1)
Getting the last record
User.last
Repo.one(from x in Model, order_by: [desc: x.id], limit: 1)
Repo.all(from x in SomeModel, where: x.greeted == true)
require IEx; IEx.pry
Run the server with the following command:
iex -S mix phx.server
# recompile
$ mix phx.gen.context Todos Todo todos title:string done:boolean
* creating lib/live_view_todos/todos/todo.ex
* creating priv/repo/migrations/20210403184352_create_todos.exs
* creating lib/live_view_todos/todos.ex
* injecting lib/live_view_todos/todos.ex
* creating test/live_view_todos/todos_test.exs
* injecting test/live_view_todos/todos_test.exs