简体   繁体   English

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

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

(Please note: Noob here so please ELI5, thanks.) (请注意:这里是菜鸟,请使用 ELI5,谢谢。)

Code Snippet:代码片段:

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

What's causing this warning and what's the correct resolution?导致此警告的原因是什么?正确的解决方法是什么? Thanks for taking a moment to help out :)感谢您抽出时间来帮忙:)

Ecto.Repo.insert_all/3 is a callback .Ecto.Repo.insert_all/3是一个回调 That said, it is to be implemented by your repo module.也就是说,它将由您的repo 模块实现。

would call it whenever she desires she needs to insert several records into your repository. 会在她需要将多条记录插入您的存储库时调用它。

The good news is if you don't need some very specific implementation, provides a naïve one for you (don't be scared by the word “naïve,” it's fine in 99% of cases.)好消息是,如果您不需要一些非常具体的实现, 为您提供了一个简单的实现(不要被“naïve”这个词吓到,在 99% 的情况下都可以。)

That said, you need to call insert_all/3 on your repo , which calls use Ecto.Repo (the latter macro is the one which would inject all the default implementations and more .)也就是说,您需要在您的 repo上调用insert_all/3 ,它调用use Ecto.Repo (后一个宏将注入所有默认实现等。)


Sidenote: I am unsure what are you actually trying to achieve, the rest of the code seems to be inconsistent as well, but since Wallet is the guy who calls use Ecto.Repo and hence who plays the role of Repo in your application, calling Wallet.insert_all/3 (or not fully qualified insert_all/3 since we are inside the very same module,) would be a great start to dig further.旁注:我不确定你真正想要实现什么,其余的代码似乎也不一致,但由于Wallet是调用use Ecto.Repo ,因此他在你的应用程序中扮演Repo的角色,调用Wallet.insert_all/3 (或非完全限定的insert_all/3因为我们在同一个模块中)将是进一步挖掘的良好开端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM