Skip to content

Instantly share code, notes, and snippets.

@ACBullen
Created October 23, 2018 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ACBullen/252ab77d95d526e670d36aed07338040 to your computer and use it in GitHub Desktop.
Save ACBullen/252ab77d95d526e670d36aed07338040 to your computer and use it in GitHub Desktop.
Repo.stream example
OldFoo
|> Repo.stream()
|> Stream.each(fn foo ->
new_foo =
NewFoo
|> where([nf], nf.name == ^foo.name)
|> Repo.one()
Bar
|> where([b], b.foo_id == ^foo.id)
|> Repo.stream()
|> Stream.each(fn bar ->
Bar.update(bar, %{foo_id: new_foo.id})
end
|> Stream.run
end)
|> Stream.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment