Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 lib/ecto/adapters/myxql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -671,14 +671,14 @@ if Code.ensure_loaded?(MyXQL) do
end

defp expr({{:., _, [{:parent_as, _, [as]}, field]}, _, []}, _sources, query)
when is_atom(field) do
when is_atom(field) or is_binary(field) do
{ix, sources} = get_parent_sources_ix(query, as)
{_, name, _} = elem(sources, ix)
[name, ?. | quote_name(field)]
end

defp expr({{:., _, [{:&, _, [idx]}, field]}, _, []}, sources, _query)
when is_atom(field) do
when is_atom(field) or is_binary(field) do
{_, name, _} = elem(sources, idx)
[name, ?. | quote_name(field)]
end
Expand Down
5 changes: 3 additions & 2 deletions lib/ecto/adapters/postgres/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,13 @@ if Code.ensure_loaded?(Postgrex) do
end

defp expr({{:., _, [{:parent_as, _, [as]}, field]}, _, []}, _sources, query)
when is_atom(field) do
when is_atom(field) or is_binary(field) do
{ix, sources} = get_parent_sources_ix(query, as)
quote_qualified_name(field, sources, ix)
end

defp expr({{:., _, [{:&, _, [idx]}, field]}, _, []}, sources, _query) when is_atom(field) do
defp expr({{:., _, [{:&, _, [idx]}, field]}, _, []}, sources, _query)
when is_atom(field) or is_binary(field) do
quote_qualified_name(field, sources, idx)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ecto/adapters/tds/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ if Code.ensure_loaded?(Tds) do
end

defp expr({{:., _, [{:parent_as, _, [as]}, field]}, _, []}, _sources, query)
when is_atom(field) do
when is_atom(field) or is_binary(field) do
{ix, sources} = get_parent_sources_ix(query, as)
{_, name, _} = elem(sources, ix)
[name, ?. | quote_name(field)]
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule EctoSQL.MixProject do
if path = System.get_env("ECTO_PATH") do
{:ecto, path: path}
else
{:ecto, "~> 3.12"}
{:ecto, git: "https://github.com/greg-rychlewski/ecto.git", branch: "string_field_name"}
end
end

Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
"ecto": {:hex, :ecto, "3.12.0", "9014a3ccac7f91e680b9d237d461ebe3d4e16d62ca8e355d540e2c6afdc28309", [: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", "41e781a76e131093af8e1edf68b1319bf320878faff58da41ffa4b10fc6ff678"},
"ecto": {:git, "https://github.com/greg-rychlewski/ecto.git", "ee1a5714b10862de7e3fe85e80f042461a07e41c", [branch: "string_field_name"]},
"ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"},
"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.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},
Expand Down
10 changes: 10 additions & 0 deletions test/ecto/adapters/myxql_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,16 @@ defmodule Ecto.Adapters.MyXQLTest do
end)
end

test "field/2 with string name" do
query = from(s in "schema", select: field(s, "x")) |> plan(:all) |> all()
assert query == ~s{SELECT s0.`x` FROM `schema` AS s0}

query =
from(s in "schema", as: :schema, select: field(as(:schema), "x")) |> plan(:all) |> all()

assert query == ~s{SELECT s0.`x` FROM `schema` AS s0}
end

# DDL

import Ecto.Migration,
Expand Down
10 changes: 10 additions & 0 deletions test/ecto/adapters/postgres_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,16 @@ defmodule Ecto.Adapters.PostgresTest do
end)
end

test "field/2 with string name" do
query = from(s in "schema", select: field(s, "x")) |> plan(:all) |> all()
assert query == ~s{SELECT s0."x" FROM "schema" AS s0}

query =
from(s in "schema", as: :schema, select: field(as(:schema), "x")) |> plan(:all) |> all()

assert query == ~s{SELECT s0."x" FROM "schema" AS s0}
end

# DDL

alias Ecto.Migration.Reference
Expand Down
10 changes: 10 additions & 0 deletions test/ecto/adapters/tds_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,16 @@ defmodule Ecto.Adapters.TdsTest do
end)
end

test "field/2 with string name" do
query = from(s in "schema", select: field(s, "x")) |> plan(:all) |> all()
assert query == ~s{SELECT s0.[x] FROM [schema] AS s0}

query =
from(s in "schema", as: :schema, select: field(as(:schema), "x")) |> plan(:all) |> all()

assert query == ~s{SELECT s0.[x] FROM [schema] AS s0}
end

## DDL

import Ecto.Migration,
Expand Down
Loading