compiler-errorselixirwarningsectoundefined-function

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


(Please note: Noob here so please ELI5, thanks.)

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 :)


Solution

  • Ecto.Repo.insert_all/3 is a callback. That said, it is to be implemented by your repo module.

    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.)

    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.)


    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.