Using this answer Ecto IN clauses with tuples - #16 by alex_weinberger I could do it. So at the end, this is what I did:
def delete_skus_by_id(list) do
queryable =
from s in SKUStore,
inner_join:
j in fragment(
"SELECT DISTINCT * FROM jsonb_to_recordset(?) AS j(sku_id int, store_id int)",
^list
),
on: s.sku_id == j.sku_id and s.store_id == j.store_id
Ecto.Multi.new()
|> Ecto.Multi.delete_all(:delete_all, queryable, on_conflict: :nothing)
|> Repo.transaction()
|> case do
{:ok, _} ->
%{rows_affected: length(list), errors: []}
{
:error,
_,
%Ecto.Changeset{
changes: changes,
errors: errors
},
_
} ->
%{
rows_affected: 0,
errors: "Changes #{changes} couldn't be created because #{inspect(errors)}"
}
end
end