Hello,
I have found lovely CSV library that I will be using to insert CSV files into postgres.
But there are some issues I am wondering about, as I am fresh in elixir.
Ok, here is the sample code I will be using to insert the CSV into DB:
File.stream!("ignore/customers.csv")
|> CSV.decode
|> Enum.each(fn
{:ok, [id, nm, csr, sal]} ->
Customer.changeset(%Customer{},
%{masterid: id,
custname: nm,
csrid: String.to_integer(csr),
salesid: String.to_integer(sal)})
|> Repo.insert
{:error, message} ->
# Whatever you want to do with invalid rows
end)
My questions are:
-
In the
Enum.eachwhat is the time interval between each call to theRepo.insert? can I control this to make sure that my DB won’t get over-pumped with queries? -
As I need to implement a progress bar in the browser while the CSV being inserted into DB, Can I broadcast a progress message in successful
Enum.eachto client using channels? for ex: after|> Repo.insertto broadcast message as:
MyApp.Endpoint.broadcast client_topic, “progress”, %{
progress: progress_number
}






















