From 9902588d13d804143facaed00fd5a277ae786fea Mon Sep 17 00:00:00 2001 From: Sven Riedel Date: Mon, 16 Dec 2024 08:21:24 +0100 Subject: [PATCH] Add Ecto.Query.ByExpr structs for ecto 3.12+ next to the old Ecto.Query.QueryExpr structs --- lib/mongo_ecto/normalized_query.ex | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/mongo_ecto/normalized_query.ex b/lib/mongo_ecto/normalized_query.ex index 14518e9..4f288e8 100644 --- a/lib/mongo_ecto/normalized_query.ex +++ b/lib/mongo_ecto/normalized_query.ex @@ -769,19 +769,28 @@ 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