From 96b84e1b9ab50e4db4f17599b662d488c870d3b7 Mon Sep 17 00:00:00 2001 From: Masanori Iwasaki Date: Wed, 1 Jul 2020 14:33:01 +0900 Subject: [PATCH] fix where in query --- lib/etso/ets/match_specification.ex | 6 ++++++ test/northwind/repo_test.exs | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/etso/ets/match_specification.ex b/lib/etso/ets/match_specification.ex index d594a42..8f2520d 100644 --- a/lib/etso/ets/match_specification.ex +++ b/lib/etso/ets/match_specification.ex @@ -79,6 +79,12 @@ defmodule Etso.ETS.MatchSpecification do field_name end + defp resolve_field_values(params, {:^, [], [start, stop]}) do + for index <- start..(stop - 1) do + Enum.at(params, index) + end + end + defp resolve_field_values(params, {:^, [], indices}) do for index <- indices do Enum.at(params, index) diff --git a/test/northwind/repo_test.exs b/test/northwind/repo_test.exs index 9bcb787..744b30c 100644 --- a/test/northwind/repo_test.exs +++ b/test/northwind/repo_test.exs @@ -35,6 +35,15 @@ defmodule Northwind.RepoTest do |> Repo.all() end + test "Where In" do + res = + Model.Employee + |> where([x], x.employee_id in ^[3, 5, 7]) + |> Repo.all() + assert length(res) == 3 + assert res |> Enum.map(& &1.employee_id) |> Enum.sort() == [3, 5, 7] + end + test "Select Where" do Model.Employee |> where([x], x.title == "Vice President Sales" and x.first_name == "Andrew")