compiler-errors - 警告 : Ecto. Repo.insert_all/3 未定义或私有(private)

标签 compiler-errors elixir warnings ecto undefined-function

(请注意:这里是菜鸟,所以请 ELI5,谢谢。)

代码片段:

defmodule Wallet do
    use Ecto.Repo,
    otp_app: :arbit,
    adapter: Ecto.Adapters.Postgres
    alias Ecto.Repo
    #use Genserver

    require ArbitDB.WalletBalance

    def refresh_db do
        updated_balances = liquid_holdings()
        Repo.insert_all(WalletBalance, updated_balances, 
            on_conflict: :replace_all_except_primary_key, conflict_target: :value_USD)
    end



$ iex -S mix
Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Compiling 1 file (.ex)
warning: Ecto.Repo.insert_all/3 is undefined or private

是什么导致了这个警告,正确的解决方法是什么?感谢您花点时间提供帮助:)

最佳答案

Ecto.Repo.insert_all/3 是一个回调。也就是说,它将由您的 repo 模块实现。

每当她需要将多条记录插入您的存储库时,都会调用它。

好消息是,如果您不需要一些非常具体的实现, provides a naïve one对你来说(不要被“天真”这个词吓到,在 99% 的情况下都可以。)

也就是说,您需要调用 insert_all/3在你的 repo 上,它调用 use Ecto.Repo (后一个宏是注入(inject)所有 default implementations and more 的宏。)

旁注:我不确定您实际上想要实现什么,其余代码似乎也不一致,但由于 Wallet是给 use Ecto.Repo 打电话的人因此谁扮演 Repo 的角色在您的应用程序中,调用 Wallet.insert_all/3 (或者不完全限定insert_all/3,因为我们在同一个模块中,)将是进一步挖掘的一个很好的开始。

关于compiler-errors - 警告 : Ecto. Repo.insert_all/3 未定义或私有(private),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60423948/

相关文章:

python-3.x - 无法在生命周期内导入估计模块

sql - 如何在SQL命令中包含值?

c++ - 在类中的 C++ 中实现枚举时出错

emacs - Emacs 中的 Elixir : UndefinedFunctionError: module is not available

elixir - 计算Ecto存储库中的条目数

python - Django 中的详细弃用警告

haskell - 来自 GHCi 提示的加载警告

java - USACO报告错误,因为我的课是公开的,应该与文件匹配

erlang - 在生产中使用 Docker 的 Elixir/Erlang 应用程序?

php - 在每种情况下,set_error_handler代码错误均为1024