From 20a81c2ce06ac6eaa6ea202f78d412537e783da6 Mon Sep 17 00:00:00 2001 From: msfstef Date: Mon, 14 Oct 2024 16:34:11 +0300 Subject: [PATCH] Address PR comments --- packages/sync-service/lib/electric/plug/utils.ex | 11 +++++------ .../sync-service/lib/electric/postgres/identifiers.ex | 5 ++--- packages/sync-service/lib/electric/shapes/shape.ex | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/sync-service/lib/electric/plug/utils.ex b/packages/sync-service/lib/electric/plug/utils.ex index d67236db05..d97ce47147 100644 --- a/packages/sync-service/lib/electric/plug/utils.ex +++ b/packages/sync-service/lib/electric/plug/utils.ex @@ -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|} """ @@ -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) diff --git a/packages/sync-service/lib/electric/postgres/identifiers.ex b/packages/sync-service/lib/electric/postgres/identifiers.ex index 350f01cc56..75c590c20d 100644 --- a/packages/sync-service/lib/electric/postgres/identifiers.ex +++ b/packages/sync-service/lib/electric/postgres/identifiers.ex @@ -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 @@ -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 diff --git a/packages/sync-service/lib/electric/shapes/shape.ex b/packages/sync-service/lib/electric/shapes/shape.ex index 75270bac90..f79cf27dbe 100644 --- a/packages/sync-service/lib/electric/shapes/shape.ex +++ b/packages/sync-service/lib/electric/shapes/shape.ex @@ -125,7 +125,7 @@ defmodule Electric.Shapes.Shape do ]}} true -> - {:ok, columns_to_select} + {:ok, Enum.sort(columns_to_select)} end end