Created
October 23, 2018 23:58
-
-
Save ACBullen/252ab77d95d526e670d36aed07338040 to your computer and use it in GitHub Desktop.
Repo.stream example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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