# `Electric.Plug.Utils`
[🔗](https://github.com/electric-sql/electric/tree/%40core/sync-service%401.6.2/packages/sync-service/lib/electric/plug/utils.ex#L1)

Utility functions for Electric endpoints, e.g. for parsing and validating
path and query parameters.

# `common_open_telemetry_attrs`

# `get_next_interval_timestamp`

```elixir
@spec get_next_interval_timestamp(integer(), binary() | nil) :: integer()
```

Calculate the next interval that should be used for long polling based on the
current time and previous interval used.

Timestamp returned is in seconds and uses a custom epoch of 9th of October 2024, UTC.

# `parse_columns_param`

```elixir
@spec parse_columns_param(binary()) :: {:ok, [String.t(), ...]} | {:error, term()}
```

Parse columns parameter from a string consisting of a comma separated list
of potentially quoted column names into a sorted list of strings.

## Examples
    iex> Electric.Plug.Utils.parse_columns_param("")
    {:error, "Invalid zero-length delimited identifier"}
    iex> Electric.Plug.Utils.parse_columns_param("foo,")
    {:error, "Invalid zero-length delimited identifier"}
    iex> Electric.Plug.Utils.parse_columns_param("id")
    {:ok, ["id"]}
    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, [~S|fo"o|, "bar"]}
    iex> Electric.Plug.Utils.parse_columns_param(~S|"id,"name"|)
    {:error, ~S|Invalid unquoted identifier contains special characters: "id|}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
