Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msfstef committed Oct 14, 2024
1 parent 5e0f2ec commit 20a81c2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
11 changes: 5 additions & 6 deletions packages/sync-service/lib/electric/plug/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ defmodule Electric.Plug.Utils do
{:error, "Invalid zero-length delimited identifier"}
iex> Electric.Plug.Utils.parse_columns_param("id")
{:ok, ["id"]}
iex> Electric.Plug.Utils.parse_columns_param("beta,alpha")
{:ok, ["alpha", "beta"]}
iex> Electric.Plug.Utils.parse_columns_param("id,name")
{:ok, ["id", "name"]}
iex> Electric.Plug.Utils.parse_columns_param(~S|"PoT@To",PoTaTo|)
{:ok, ["PoT@To", "potato"]}
iex> Electric.Plug.Utils.parse_columns_param(~S|"PoTaTo,sunday",foo|)
{:ok, ["PoTaTo,sunday", "foo"]}
iex> Electric.Plug.Utils.parse_columns_param(~S|\"fo\"\"o\",bar|)
{:ok, ["bar", ~S|fo"o|]}
iex> Electric.Plug.Utils.parse_columns_param(~S|"fo""o",bar|)
{:ok, [~S|fo"o|, "bar"]}
iex> Electric.Plug.Utils.parse_columns_param(~S|"id,"name"|)
{:error, ~S|Invalid unquoted identifier contains special characters: "id|}
"""
Expand All @@ -40,9 +40,8 @@ defmodule Electric.Plug.Utils do
end)
|> then(fn result ->
case result do
# sort to keep selected columns identical
# TODO: convert output to MapSet?
parsed_cols when is_list(parsed_cols) -> {:ok, Enum.sort(parsed_cols)}
parsed_cols when is_list(parsed_cols) -> {:ok, Enum.reverse(parsed_cols)}
{:error, reason} -> {:error, reason}
end
end)
Expand Down
5 changes: 2 additions & 3 deletions packages/sync-service/lib/electric/postgres/identifiers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule Electric.Postgres.Identifiers do

defp unescape_quotes(string) do
string
|> String.replace(~r/""/, "\"")
|> String.replace(~r/""/, ~S|"|)
end

defp valid_unquoted_identifier?(identifier) do
Expand Down Expand Up @@ -104,8 +104,7 @@ defmodule Electric.Postgres.Identifiers do

truncated_ident =
if String.length(ident) >= @namedatalen do
result = String.slice(downcased_ident, 0, @namedatalen)
result
String.slice(downcased_ident, 0, @namedatalen)
else
downcased_ident
end
Expand Down
2 changes: 1 addition & 1 deletion packages/sync-service/lib/electric/shapes/shape.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ defmodule Electric.Shapes.Shape do
]}}

true ->
{:ok, columns_to_select}
{:ok, Enum.sort(columns_to_select)}
end
end

Expand Down

0 comments on commit 20a81c2

Please sign in to comment.