PgRest.Planner.Params (PgRest v0.2.0)

Copy Markdown View Source

Splits the query string of a read into per-embed-path groups.

A group is %{where: [...], order: nil | [OrderTerm], ranges: [{"limit" | "offset", v}], custom: [{key, value}]} keyed by the embed path ([] is the root). select, order (root), the reserved columns and on_conflict, and keys without a value never become filters; limit and offset are collected per path.

Summary

Functions

A group with nothing in it.

Groups params (valueless keys already dropped) by embed path. declared are the root resource's custom param names.

The last value of key, or nil.

Whether key is a logic tree key (or, and, optionally behind an embed path).

The reserved parameters that do not shape a representation either (columns=, paging).

Parses the select parameter of params (valueless keys already dropped): the select tree, * when the request has none.

The embed path a query-string parameter targets, parsed with the same grammar as group/2: [] for the root (and for a parameter that does not parse, which the planner reports). declared are the custom params. A key that merely contains a dot (settings->>"a.b") is a root filter: embeddedness comes from the parsed path only.

The query parameters that never filter rows (PgRest.Write reads them too).

Whether key is never a plain filter or RPC argument: a reserved parameter, a logic key or an embed-path order/limit/offset.

The root group of groups (an empty group when the request has no root parameter).

Groups the request parameters params (group/2, valueless keys dropped) and returns the root group.

The parameters that carry a value (a valueless key never filters).

Types

group()

@type group() :: %{
  where: list(),
  order: nil | [PgRest.AST.OrderTerm.t()],
  ranges: [{String.t(), String.t()}],
  custom: [{String.t(), String.t()}]
}

Functions

empty_group()

@spec empty_group() :: group()

A group with nothing in it.

group(params, declared)

@spec group([{String.t(), String.t()}], [String.t()]) ::
  {:ok, %{required([String.t()]) => group()}} | {:error, PgRest.Error.t()}

Groups params (valueless keys already dropped) by embed path. declared are the root resource's custom param names.

last_value(params, key)

@spec last_value([{String.t(), String.t()}], String.t()) :: String.t() | nil

The last value of key, or nil.

logic_key?(key)

@spec logic_key?(String.t()) :: boolean()

Whether key is a logic tree key (or, and, optionally behind an embed path).

not_shaping()

@spec not_shaping() :: [String.t()]

The reserved parameters that do not shape a representation either (columns=, paging).

parse_select(params)

@spec parse_select([{String.t(), String.t()}]) ::
  {:ok, [PgRest.AST.Embed.item()]} | {:error, PgRest.Error.t()}

Parses the select parameter of params (valueless keys already dropped): the select tree, * when the request has none.

path(key, value, declared)

@spec path(String.t(), term(), [String.t()]) :: [String.t()]

The embed path a query-string parameter targets, parsed with the same grammar as group/2: [] for the root (and for a parameter that does not parse, which the planner reports). declared are the custom params. A key that merely contains a dot (settings->>"a.b") is a root filter: embeddedness comes from the parsed path only.

reserved()

@spec reserved() :: [String.t()]

The query parameters that never filter rows (PgRest.Write reads them too).

reserved_key?(key)

@spec reserved_key?(String.t()) :: boolean()

Whether key is never a plain filter or RPC argument: a reserved parameter, a logic key or an embed-path order/limit/offset.

root(groups)

@spec root(%{required([String.t()]) => group()}) :: group()

The root group of groups (an empty group when the request has no root parameter).

root_group(params, declared)

@spec root_group([{String.t(), String.t() | nil}], [String.t()]) ::
  {:ok, group()} | {:error, PgRest.Error.t()}

Groups the request parameters params (group/2, valueless keys dropped) and returns the root group.

string_pairs(params)

@spec string_pairs([{String.t(), String.t() | nil}]) :: [{String.t(), String.t()}]

The parameters that carry a value (a valueless key never filters).