PgRest.Parser (PgRest v0.1.0)

Copy Markdown View Source

Parses PostgREST-style URL parameters into structured ASTs.

Handles filters, select, order, pagination, embed filters (dot-notation), custom params, on_conflict, and columns.

Summary

Functions

Parses a map of URL query parameters into a structured result.

Parses an operator.value string into {:ok, operator, value}.

Functions

parse(params, opts \\ [])

@spec parse(
  map(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Parses a map of URL query parameters into a structured result.

Options

  • :allowed_fields - list of atoms restricting which fields can be filtered
  • :max_limit - integer clamping the maximum limit value

Returns

{:ok, parsed} where parsed contains:

  • :filters - list of filter AST nodes for the root resource
  • :embed_filters - map of embed name to list of filter AST nodes
  • :select - select AST or nil
  • :order - order AST or nil
  • :limit, :offset - pagination values
  • :custom_params - params not matching any known field or standard param
  • :on_conflict, :columns - upsert-related params

parse_operator_value(str)

@spec parse_operator_value(String.t()) :: {:ok, atom(), term()} | {:error, term()}

Parses an operator.value string into {:ok, operator, value}.

Examples

iex> PgRest.Parser.parse_operator_value("eq.active")
{:ok, :eq, "active"}

iex> PgRest.Parser.parse_operator_value("in.(a,b,c)")
{:ok, :in, ["a", "b", "c"]}