Skip to content

Commit

Permalink
Merge pull request #101 from circles-learning-labs/select
Browse files Browse the repository at this point in the history
support Ecto Query select tuples, like select: {record.field_1, recor…
  • Loading branch information
bernardd committed Jun 16, 2021
2 parents c67b9af + bcf7283 commit dbdc7f1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ecto_adapters_dynamodb.ex
Expand Up @@ -1516,6 +1516,9 @@ defmodule Ecto.Adapters.DynamoDB do

defp construct_types_from_select_fields(%Ecto.Query.SelectExpr{expr: expr}) do
case expr do
{:{}, [], clauses = [{{:., [type: type], [{:&, [], [0]}, field]}, [], []} | _]} ->
for {{:., [type: type], [{:&, [], [0]}, field]}, [], []} <- clauses, do: {field, type}

{_, _, [0]} ->
[]

Expand Down
27 changes: 27 additions & 0 deletions test/ecto_adapters_dynamodb_test.exs
Expand Up @@ -823,6 +823,33 @@ defmodule Ecto.Adapters.DynamoDB.Test do
|> length() == 0
end

test "tuple argument for select" do
id = "person:tuple_argument_for_select"
email = "hj@test.com"

TestRepo.insert(%Person{
id: id,
first_name: "heebie",
last_name: "jeebie",
email: email,
age: 12553
})

assert from(p in Person,
where: p.first_name == "heebie",
select: {p.email}
)
|> TestRepo.all() == [{email}]

assert from(p in Person,
where: p.first_name == "heebie",
select: {p.id, p.email}
)
|> TestRepo.all() == [{id, email}]
end

# Private

defp make_list_of_people_for_batch_insert(total_records) do
for i <- 0..total_records, i > 0 do
id_string = :crypto.strong_rand_bytes(16) |> Base.url_encode64() |> binary_part(0, 16)
Expand Down

0 comments on commit dbdc7f1

Please sign in to comment.