Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for where/in queries #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/etso/ets/match_specification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/northwind/repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down