使用 Ecto Elixir 从 Postgres 获取记录

Getting Record from Postgres using Ecto Elixir

我正在尝试通过电子邮件获取用户。 getting merge函数是不存在的,连merge函数我都没有写

代码

def get_user_by_email(email) do
    User
    |> preload(:exchange_accounts)
    |> preload(:pos_account)
    |> Repo.all(from u in User, where: u.email == ^email)
  end

错误

iex(58)> AAK.POS.HelperFunction.get_user_by_email("sohaibanwaar36@gmail.com")
** (FunctionClauseError) no function clause matching in Keyword.merge/2    
    
    The following arguments were given to Keyword.merge/2:
    
        # 1
        []
    
        # 2 
        #Ecto.Query<from u0 in AAK.Accounts.User,
         where: u0.email == ^"sohaibanwaar36@gmail.com">
    
    Attempted function clauses (showing 3 out of 3):
    
        def merge(keywords1, []) when is_list(keywords1)
        def merge([], keywords2) when is_list(keywords2)
        def merge(keywords1, keywords2) when is_list(keywords1) and is_list(keywords2) 
    
    (elixir 1.11.1) lib/keyword.ex:764: Keyword.merge/2
    (aak 0.1.0) lib/aak/repo.ex:4: AAK.Repo.all/2

应该将 Ecto.Query.preload/3 with a query, or Ecto.Repo.preload/3 与结构一起使用,而不是混合使用。

下面是带有查询的变体。

def get_user_by_email(email) do
  Repo.all(
    from u in User,
    where: u.email == ^email,
    preload: ~w|exchange_accounts pos_account|a
  )
end