Maxximiliann

Maxximiliann

How to generalize the Repo.delete callback()?

Goal:
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)
      Repo.delete(record)
    end)
  end
end

Result:

** (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?

Marked As Solved

LostKobrakai

LostKobrakai

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

Where Next?

Popular in Questions Top

logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New

We're in Beta

About us Mission Statement