Skip to content

Commit 7224c12

Browse files
Handle constant/1 unpacking in Ecto instead of adapters (#4696)
1 parent 1335593 commit 7224c12

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

lib/ecto/query/api.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ defmodule Ecto.Query.API do
561561
562562
This would be transformed into
563563
564-
from p in Post, where: fragment(? in (?,?,?), p.id, constant(1), ^2, ^3)
564+
from p in Post, where: fragment(? in (?,?,?), p.id, constant(^1), ^2, ^3)
565565
"""
566566
def splice(list), do: doc!([list])
567567

lib/ecto/query/builder.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,7 @@ defmodule Ecto.Query.Builder do
781781
case expr do
782782
{:^, _, [expr]} ->
783783
checked = quote do: Ecto.Query.Builder.constant!(unquote(expr))
784-
escaped = {:{}, [], [:constant, [], [checked]]}
785-
{escaped, params_acc}
784+
{checked, params_acc}
786785

787786
_ ->
788787
error!(

test/ecto/query_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,8 @@ defmodule Ecto.QueryTest do
11191119

11201120
assert {:fragment, _, select_parts} = query.select.expr
11211121
assert {:fragment, _, limit_parts} = query.limit.expr
1122-
assert [raw: "", expr: {:constant, _, ["hi"]}, raw: ""] = select_parts
1123-
assert [raw: "", expr: {:constant, _, [1]}, raw: ""] = limit_parts
1122+
assert [raw: "", expr: "hi", raw: ""] = select_parts
1123+
assert [raw: "", expr: 1, raw: ""] = limit_parts
11241124

11251125
msg = "constant(^value) expects `value` to be a string or a number, got `%{}`"
11261126

@@ -1186,7 +1186,7 @@ defmodule Ecto.QueryTest do
11861186
raw: ",",
11871187
expr: 2,
11881188
raw: ",",
1189-
expr: {:constant, _, [3]},
1189+
expr: 3,
11901190
raw: ",",
11911191
expr: {:^, _, [1]},
11921192
raw: ")"

0 commit comments

Comments
 (0)