(请注意:这里是菜鸟,所以请 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 模块实现。
ecto每当她需要将多条记录插入您的存储库时,都会调用它。
好消息是,如果您不需要一些非常具体的实现,ecto 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/