How to decrement a field value?

Here is my test function to increment a field value

def update(name, increment) do
  query = from u in User, where: u.name == ^name  
  Repo.update_all(query, inc: [score: increment])
end

But I don’t know how to decrement the field value.

And, if the score decrement to 0, I want update the User.statue = “INVALID”, how to do?

To decrement, just do inc: [score: -increment]).

2 Likes

Thanks