Problem to call function inside macro and improve custom repo crud macro

Hi, for practicing I wanted to create a custom CRUD function which is using Repo. But on the way I have some problems with basic.

Problem 1:

in this section I have 2 problems, at first I can’t call my function inside my module Macro.escape. with this it works but this output is very Raw and different with regular repo outputs.

code:


then I tried this:
edited_record = Macro.escape(edit_record(unquote(attr), module_selected, error_atom, repo))
unquote(edited_record)

but this shows me this Error:

warning: variable "edited_record" does not exist and is being expanded to "edited_record()", please use parentheses to remove the ambiguity or change the variable name
  lib/helpers/crud.ex:32: MishkaDatabase.CRUD.crud_edit/1


== Compilation error in file lib/helpers/crud.ex ==
** (CompileError) lib/helpers/crud.ex:32: undefined function edited_record/0
    (elixir 1.11.2) src/elixir_locals.erl:114: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
    (stdlib 3.13.2) erl_eval.erl:680: :erl_eval.do_apply/6

ohhh this was very hard :sob:, but there is a problem more:
I cant call any function which is private or not inside a quote and it shows me cant know the def selected like , by the way I tried to call apply but that did not work too. :nauseated_face:

  defp uuid(id) do
    case Ecto.UUID.cast(id) do
      {:ok, record_id} -> {:ok, :uuid, record_id}
      _ -> {:error, :uuid}
    end
  end

Problem 2:

how to improve a macro like this, any suggest, I think my code can be better.

Thanks.