View Source Electric.Plug.Utils (electric v0.9.5)
Utility functions for Electric endpoints, e.g. for parsing and validating path and query parameters.
Summary
Functions
Calculate the next interval that should be used for long polling based on the current time and previous interval used.
Parse columns parameter from a string consisting of a comma separated list of potentially quoted column names into a sorted list of strings.
Functions
Link to this function
get_next_interval_timestamp(long_poll_timeout_ms, prev_interval \\ nil)
View SourceCalculate 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 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|}