When an ecto function provides a "repo" variable, is it safe to go around it?

Some Ecto functions give you a “repo” variable, such as Ecto.Changeset.prepare_changes or Ecto.Multi.run.

The docs don’t say you must use this, AFAIK, I think it’s just convenience? Can I ignore it and use my normal convenience functions or will I get bitten by some hard-to-track DB consistency issue?

|> Ecto.Multi.run(:do_it, fn _repo, %{post: post} ->
  # doesnt pass the db access "through" repo
1 Like

I believe this is supplied for you in case your project has several repos (which happens very often in commercial projects).

I personally do use the variable for consistency but if you only have one repo, you can skip it without any negative repercussions. It makes no difference.


Yeah it just twigged to me that the reason you might care is if you’re not 100% sure which repo.