警告:Ecto.Repo.insert_all/3 未定义或私有

warning: Ecto.Repo.insert_all/3 is undefined or private

(请注意:这里是菜鸟所以请 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 是一个 回调。也就是说,它将由你的 回购模块实现。

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

好消息是,如果您不需要一些非常具体的实现, 为您提供了一个简单的实现(不要被这个词吓到“天真”,在 99% 的情况下都可以。)

就是说,您需要在 您的存储库 上调用 insert_all/3,它会调用 use Ecto.Repo(后一个宏会 注入所有default implementations and more.)


旁注:我不确定你到底想实现什么,其余代码似乎也不一致,但因为 Wallet 是那个人谁调用 use Ecto.Repo,因此谁在您的应用程序中扮演 Repo 的角色,调用 Wallet.insert_all/3(或者不完全限定 insert_all/3,因为我们在同一个模块中)会成为进一步挖掘的良好开端。