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)
|
2021-09-24 14:43:41 +02:00
|
|
|
|> Enum.map(fn x -> %Clothes{game: x["game"], location: x["location"], name: x["name"], color: x["color"], type: x["type"]} end)
|
2021-07-01 13:03:34 +02:00
|
|
|
|> Enum.each(fn x -> Repo.insert!(x) end)
|
|
|
|
end
|
|
|
|
end
|
2021-06-30 14:03:08 +02:00
|
|
|
|
2021-09-24 14:43:41 +02:00
|
|
|
Repo.insert! %Clothes{game: "Tlapka", location: "Tlapkov", type: "hat", name: "Tlapka Hat", color: "Blue"}
|
2021-07-01 13:03:34 +02:00
|
|
|
Parser.parse()
|