ruby Sequel查询ecto elixir

时间:2016-06-21 12:00:08

标签: elixir ecto

我用ruby写的这个表达

vendors = vendors.where(%("known_macs" @> ARRAY[?]), params[:mac].upcase[0, 8])

我想在ecto中写这个...我的整个结构是

  def index(conn, params) do
    known_macs =
      params["mac"]
      |> upcase

    vendors =
      from(v in Vendor)
      |> with_exid_if_given(params["id"])
      |> with_name_if_given(params["name"])
      |> with_known_macs_if_given(known_macs)
      |> preload(:vendor_models)
      |> Repo.all

    conn
    |> render(VendorView, "index.json", %{vendors: vendors})
  end

  defp with_exid_if_given(query, nil), do: query
  defp with_exid_if_given(query, exid) do
    query
    |> where([v], v.exid == ^exid)
  end

  defp with_name_if_given(query, nil), do: query
  defp with_name_if_given(query, name) do
    query
    |> where([v], like(v.name, ^name))
  end

  defp with_known_macs_if_given(query, nil), do: query
  defp with_known_macs_if_given(query, known_macs) do
    query
    |> where([v], %("known_macs" @> ARRAY[?]), known_macs)
  end

我不知道如何检查查询中的mac地址。当我传递一个mac地址然后在ruby查询中它看起来像#<Sequel::Postgres::Dataset: "SELECT * FROM \"vendors\" WHERE (\"known_macs\" @> ARRAY['8C:11:CB'])">

1 个答案:

答案 0 :(得分:0)

这可以像这样完成

Array.prototype.slice.call(document.querySelectorAll(".main .sub")).forEach(function(el){
  el.click();
})