How to generalize the Repo.delete callback()?

Generalizing the Repo.delete callback().

Initial attempt:

defmodule DB_API do
  def delete_single_record(DB.Foo = table_name, :uid = key, "ABCD123" = identifier) do
    Repo.transaction(fn ->
      record = Repo.get_by!(table_name, key, identifier)


** (Protocol.UndefinedError) protocol Enumerable not implemented for :name of type Atom. This protocol is implemented for the following type(s): Ecto.Adapters.SQL.Stream, Postgrex.Stream, DBConnection.PrepareStream, DBConnection.Stream, IO.Stream, GenEvent.Stream, MapSet, Stream, HashSet, Range, File.Stream, HashDict, Date.Range, Map, Function, List
    (elixir 1.12.2) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.12.2) lib/enum.ex:141: Enumerable.reduce/3
    (elixir 1.12.2) lib/enum.ex:3952: Enum.reverse/1
    (elixir 1.12.2) lib/enum.ex:3311: Enum.to_list/1
    (ecto 3.4.6) lib/ecto/repo/queryable.ex:428: Ecto.Repo.Queryable.query_for_get_by/2
    (ecto 3.4.6) lib/ecto/repo/queryable.ex:74: Ecto.Repo.Queryable.get_by!/4
    (arbit 21.7.9) lib/Helper Modules/DB_API.ex:47: anonymous fn/3 in DB_API.delete_single_record/3
    (ecto_sql 3.4.5) lib/ecto/adapters/sql.ex:875: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4

What would be the best strategy to generalizing this callback, assuming this is even possible?

Repo.delete only works with schemas. For lower level access to delete use Repo.delete_all.

1 Like