pokemon-couture/priv/repo/seeds.exs

27 lines
864 B
Elixir
Raw Normal View History

2021-06-28 11:14:14 +02:00
# Script for populating the database. You can run it as:
#
# mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
# PokemonCouture.Repo.insert!(%PokemonCouture.SomeSchema{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
2021-06-30 14:03:08 +02:00
alias PokemonCouture.Repo
alias PokemonCouture.Shops.Clothes
2021-07-01 13:03:34 +02:00
defmodule Parser do
def parse do
File.stream!("sunmoon_clothes.csv")
|> CSV.decode!(headers: :true)
# |> Enum.each(fn x -> IO.inspect(x) end)
|> Enum.map(fn x -> %Clothes{game: x["game"], location: x["location"], name: x["name"], color: x["color"]} end)
|> Enum.each(fn x -> Repo.insert!(x) end)
end
end
2021-06-30 14:03:08 +02:00
Repo.insert! %Clothes{game: "Tlapka", location: "Tlapkov", name: "Tlapka Hat", color: "Blue"}
2021-07-01 13:03:34 +02:00
Parser.parse()