Depending on the problem, you can also use upserts. If you do insert(data, on_conflict: :nothing, returning: true)
, it will do nothing if the data exists and return all fields from the database.
We also talk about it on the What’s New in Ecto 2.0 ebook (95% of it still applies to Ecto 3). http://pages.plataformatec.com.br/ebook-whats-new-in-ecto-2-0