LiveFilter.Params.Serializer (LiveFilter v0.1.8)

Copy Markdown View Source

Converts a list of active Filter structs into a PostgREST-compatible query param map.

Summary

Functions

Serializes pagination state to PostgREST-compatible URL params.

Serializes a list of filters to a PostgREST-compatible param map.

Builds a full path with raw query string.

Converts a params map to a raw query string without percent-encoding.

Functions

pagination_to_params(pagination)

@spec pagination_to_params(LiveFilter.Pagination.t()) :: map()

Serializes pagination state to PostgREST-compatible URL params.

Example

iex> pagination = %LiveFilter.Pagination{limit: 25, offset: 50}
iex> Serializer.pagination_to_params(pagination)
%{"limit" => "25", "offset" => "50"}

to_params(filters)

@spec to_params([LiveFilter.Filter.t()]) :: map()

Serializes a list of filters to a PostgREST-compatible param map.

Nil and empty string values are excluded. Date range filters produce two params (gte + lte). Ilike text filters auto-wrap with * wildcards if not already present.

to_path(base_path, params)

@spec to_path(String.t(), map()) :: String.t()

Builds a full path with raw query string.

Example

iex> Serializer.to_path("/tasks", %{"status" => "eq.active"})
"/tasks?status=eq.active"

to_query_string(params)

@spec to_query_string(map()) :: String.t()

Converts a params map to a raw query string without percent-encoding.

This produces cleaner URLs like tags=ov.{testing,bug} instead of tags=ov.%7Btesting%2Cbug%7D.

Example

iex> Serializer.to_query_string(%{"status" => "eq.active", "tags" => "ov.{a,b}"})
"status=eq.active&tags=ov.{a,b}"