elixir - How to pattern match Ecto query error -
elixir - How to pattern match Ecto query error -
like other functions in elixir (as ecto's own transactions), want pattern match handle potential errors ecto queries. this:
case repo.get!(user, id) {:ok, user} -> #do {:error, message} -> #pass error end
obviously not work, how can pattern match ecto errors ecto.notsingleresult , other potential query problems preload errors?
use repo.get
homecoming value or nil. can pattern match on expected struct or utilize if-clauses. repo.get!
raises on purpose (for cases expect struct there , not beingness there error).
elixir ecto
Comments
Post a Comment