Skip to content

Ecto 3.12: Add Query.ByExpr structs next to the old Query.QueryExpr struct matching #198

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

Merged
merged 3 commits into from
Mar 8, 2025
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
with:
otp-version: ${{ matrix.otpElixir.otp }}
elixir-version: ${{ matrix.otpElixir.elixir }}
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: |
deps
@@ -57,7 +57,7 @@ jobs:
with:
otp-version: ${{ matrix.otpElixir.otp }}
elixir-version: ${{ matrix.otpElixir.elixir }}
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: |
deps
28 changes: 21 additions & 7 deletions lib/mongo_ecto/normalized_query.ex
Original file line number Diff line number Diff line change
@@ -769,19 +769,30 @@ defmodule Mongo.Ecto.NormalizedQuery do

defp order(%Query{order_bys: order_bys} = query, {_coll, _model, pk}) do
order_bys
|> Enum.flat_map(fn %Query.QueryExpr{expr: expr} ->
Enum.map(expr, &order_by_expr(&1, pk, query))
|> Enum.flat_map(fn
%Query.QueryExpr{expr: expr} ->
Enum.map(expr, &order_by_expr(&1, pk, query))

%Query.ByExpr{expr: expr} ->
Enum.map(expr, &order_by_expr(&1, pk, query))
end)
|> map_unless_empty
end

defp command(:update, %Query{updates: updates} = query, params, {_coll, _model, pk}) do
updates
|> Enum.flat_map(fn %Query.QueryExpr{expr: expr} ->
Enum.map(expr, fn {key, value} ->
value = value |> value(params, pk, query, "update clause")
{update_op(key, query), value}
end)
|> Enum.flat_map(fn
%Query.QueryExpr{expr: expr} ->
Enum.map(expr, fn {key, value} ->
value = value |> value(params, pk, query, "update clause")
{update_op(key, query), value}
end)

%Query.ByExpr{expr: expr} ->
Enum.map(expr, fn {key, value} ->
value = value |> value(params, pk, query, "update clause")
{update_op(key, query), value}
end)
end)
|> merge_keys(query, "update clause")
end
@@ -892,6 +903,9 @@ defmodule Mongo.Ecto.NormalizedQuery do
defp offset_limit(%Query.QueryExpr{expr: expr}, params, pk, query, where),
do: value(expr, params, pk, query, where)

defp offset_limit(%Query.ByExpr{expr: expr}, params, pk, query, where),
do: value(expr, params, pk, query, where)

defp offset_limit(%Query.LimitExpr{expr: expr}, params, pk, query, where),
do: value(expr, params, pk, query, where)

2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ defmodule Mongo.Ecto.Mixfile do
[
{:credo, "~> 1.5.6", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.1.0", only: :dev, runtime: false},
{:ecto, "~> 3.10"},
{:ecto, "~> 3.12"},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:excoveralls, "~> 0.16", only: :test},
{:mongodb_driver, "~> 1.4"},
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -6,14 +6,14 @@
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.18", "e1b2be73eb08a49fb032a0208bf647380682374a725dfb5b9e510def8397f6f2", [:mix], [], "hexpm", "114a0e85ec3cf9e04b811009e73c206394ffecfcc313e0b346de0d557774ee97"},
"ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"},
"ecto": {:hex, :ecto, "3.12.5", "4a312960ce612e17337e7cefcf9be45b95a3be6b36b6f94dfb3d8c361d631866", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6eb18e80bef8bb57e17f5a7f068a1719fbda384d40fc37acb8eb8aeca493b6ea"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.26.0", "1922164bac0b18b02f84d6f69cab1b93bc3e870e2ad18d5dacb50a9e06b542a3", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2775d66e494a9a48355db7867478ffd997864c61c65a47d31c4949459281c78d"},
"excoveralls": {:hex, :excoveralls, "0.16.0", "41f4cfbf7caaa3bc2cf411db6f89c1f53afedf0f1fe8debac918be1afa19c668", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "401205356482ab99fb44d9812cd14dd83b65de8e7ae454697f8b34ba02ecd916"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},

Unchanged files with check annotations Beta

defmodule Ecto.Integration.TypeTest do
use Ecto.Integration.Case, async: Application.get_env(:ecto, :async_integration_tests, true)

Check warning on line 2 in test/ecto_test/type_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/type_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/type_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/type_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/type_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/type_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead
alias Ecto.Integration.{
Custom,
assert [true] = TestRepo.all(from p in Post, where: p.public == true, select: p.public)
# Binaries
assert [^blob] = TestRepo.all(from p in Post, where: p.blob == <<0, 1>>, select: p.blob)

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, server)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, server)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, server)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (6.0, 22.3.4.26, 1.12.3, server)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (7.0, 22.3.4.26, 1.12.3, server)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (5.0, 22.3.4.26, 1.12.3, server)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (5.0, 22.3.4.26, 1.12.3, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (7.0, 23.3.4.18, 1.13.4, server)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (7.0, 22.3.4.26, 1.12.3, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (6.0, 23.3.4.18, 1.13.4, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (6.0, 22.3.4.26, 1.12.3, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (6.0, 23.3.4.18, 1.13.4, server)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (5.0, 23.3.4.18, 1.13.4, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (7.0, 23.3.4.18, 1.13.4, replica_set)

this check/guard will always yield the same result

Check warning on line 61 in test/ecto_test/type_test.exs

GitHub Actions / test (5.0, 23.3.4.18, 1.13.4, server)

this check/guard will always yield the same result
assert [^blob] = TestRepo.all(from p in Post, where: p.blob == ^blob, select: p.blob)
# UUID
query = "schema" |> where(foo: "abc") |> select([], true) |> normalize
assert_fields query, query: %{foo: "abc"}
query = "schema" |> where(foo: <<0, ?a, ?b, ?c>>) |> select([], true) |> normalize

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, server)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, server)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, server)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (6.0, 22.3.4.26, 1.12.3, server)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (7.0, 22.3.4.26, 1.12.3, server)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (5.0, 22.3.4.26, 1.12.3, server)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (5.0, 22.3.4.26, 1.12.3, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (7.0, 23.3.4.18, 1.13.4, server)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (7.0, 22.3.4.26, 1.12.3, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (6.0, 23.3.4.18, 1.13.4, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (6.0, 22.3.4.26, 1.12.3, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (6.0, 23.3.4.18, 1.13.4, server)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (5.0, 23.3.4.18, 1.13.4, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (7.0, 23.3.4.18, 1.13.4, replica_set)

this check/guard will always yield the same result

Check warning on line 387 in test/mongo_ecto/normalized_query_new_test.exs

GitHub Actions / test (5.0, 23.3.4.18, 1.13.4, server)

this check/guard will always yield the same result
assert_fields query, query: %{foo: %BSON.Binary{binary: <<0, ?a, ?b, ?c>>}}
query = "schema" |> where(foo: 123) |> select([], true) |> normalize
defmodule Ecto.Integration.RepoTest do
use Ecto.Integration.Case, async: Application.get_env(:ecto, :async_integration_tests, true)

Check warning on line 2 in test/ecto_test/repo_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/repo_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/repo_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/repo_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/repo_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/repo_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead
import Ecto.Query
defmodule Ecto.Integration.AssocTest do
use Ecto.Integration.Case, async: Application.get_env(:ecto, :async_integration_tests, true)

Check warning on line 2 in test/ecto_test/assoc_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/assoc_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/assoc_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, server)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/assoc_test.exs

GitHub Actions / test (7.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/assoc_test.exs

GitHub Actions / test (6.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead

Check warning on line 2 in test/ecto_test/assoc_test.exs

GitHub Actions / test (5.0, 24.3.4.10, 1.14.3, replica_set)

Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead
import Ecto.Query