Skip to content

Instantly share code, notes, and snippets.

@jll90
Created July 27, 2020 21:27
Show Gist options
  • Save jll90/c16f82d73e651b020f9e1ff115a61182 to your computer and use it in GitHub Desktop.
Save jll90/c16f82d73e651b020f9e1ff115a61182 to your computer and use it in GitHub Desktop.
Write CSV data to a file
f = File.stream!("Locations.csv")
%File.Stream{
line_or_bytes: :line,
modes: [:raw, :read_ahead, :binary],
path: "Locations.csv",
raw: true
}
City |> Repo.all() |> Repo.preload([:county, county: [:state]]) |> Enum.map(&([&1.id, &1.county.state.id])) |> CSV.encode() |> Stream.into(f) |> Stream.run()
:ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment