do :supervisor.start_link(__MODULE__, []) end def init([]) do # Adding repo to be sent into supervise tree = [worker(Repo, [])] supervise(tree, strategy: :one_for_one) end end
Saves to the database user = Repo.get(User, 1) #=> %User{content: "Hello} user = %{user | content: "Goodbye"} Repo.update(user) #=> %User{content: "Goodbye"} Repo.delete(user) # Deleted the database record
do user = %User{content: content} case User.validate(user) do [] -> user = Repo.insert(user) render conn, "show", user: user errors -> render conn, "new", user: user, errors: errors end end
params}) do user = Repo.get(User, id) user = %{user | content: params["content"]} case User.validate(user) do [] -> Repo.update(user) # don't do this json conn, 201, JSON.encode!(%{location: Router.user_path(id: user.id)}) errors -> json conn, errors: errors end end
= Repo.get(User, id) case user do user when is_map(user) -> Repo.delete(user) json conn, 200, JSON.encode!(%{location: Router.users_path}) _ -> redirect conn, Router.page_path(page: "unauthorized") end end