@dimitarvp it was inserting one by one. I changed it with the help of a friend and it worked. insert_all does the job as @axelson was saying. Now it looks like this:
def bulk_create(entity, items) do
Ecto.Multi.new()
|> Ecto.Multi.insert_all(:insert_all, entity, items, on_conflict: :nothing)
|> Repo.transaction()
|> case do
{:ok, _} ->
%{rows_affected: length(items), errors: []}
{
:error,
_,
%Ecto.Changeset{
changes: changes,
errors: errors
},
_
} ->
%{
rows_affected: 0,
errors: "Changes #{changes} couldn't be created because #{inspect(errors)}"
}
end
end
But the problem is that I had to take care of timestamps because insert_all doesn’t insert them. So a migration to set a default value of now() solves the issue.
So, issue solved but I still won’t know why it was closing the connection even when I set the timeout to :infinity with the previous function. BTW, now with the insert_all solution I can stick to the default timeout of 15_000ms






















