FlopRest.Operators (FlopRest v0.6.1)

Copy Markdown View Source

Maps REST-style operator strings to Flop operator strings.

Operator Reference

OperatorExampleSQL
(none)status=activestatus = 'active'
eqstatus[eq]=activestatus = 'active'
nestatus[ne]=archivedstatus != 'archived'
gtage[gt]=18age > 18
gteage[gte]=18age >= 18
ltprice[lt]=100price < 100
lteprice[lte]=100price <= 100
instatus[in]=draft,publishedstatus IN ('draft', 'published')
not_instatus[not_in]=draft,archivedstatus NOT IN ('draft', 'archived')
containstags[contains]=elixir'elixir' = ANY(tags)
not_containstags[not_contains]=go'go' != ALL(tags)
likename[like]=%john%name LIKE '%john%'
not_likename[not_like]=%test%name NOT LIKE '%test%'
like_andname[like_and]=Rubi,Rosaname LIKE '%Rubi%' AND name LIKE '%Rosa%'
like_orname[like_or]=Rubi,Rosaname LIKE '%Rubi%' OR name LIKE '%Rosa%'
ilikename[ilike]=%john%name ILIKE '%john%'
not_ilikename[not_ilike]=%test%name NOT ILIKE '%test%'
ilike_andname[ilike_and]=Rubi,Rosaname ILIKE '%Rubi%' AND name ILIKE '%Rosa%'
ilike_orname[ilike_or]=Rubi,Rosaname ILIKE '%Rubi%' OR name ILIKE '%Rosa%'
emptydeleted_at[empty]=truedeleted_at IS NULL
not_emptydeleted_at[not_empty]=truedeleted_at IS NOT NULL
searchq[search]=johnConfigurable in Flop (ILIKE by default)

Unknown operators are passed through for Flop to validate.

List Operators

The operators in, not_in, like_and, like_or, ilike_and, and ilike_or automatically split comma-separated string values into lists. A single value (no commas) is passed through as a string, allowing Flop to apply its own parsing (e.g. whitespace splitting for like_and).

Use the bracket [] syntax if values themselves contain commas:

status[in][]=draft&status[in][]=has,comma

Summary

Functions

Returns whether the given REST operator expects a list value.

Converts a REST operator string to the corresponding Flop operator.

Converts a Flop operator atom to the corresponding REST operator string.

Functions

list_operator?(op)

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

Returns whether the given REST operator expects a list value.

List operators will have comma-separated string values automatically split into lists during filter extraction.

Examples

iex> FlopRest.Operators.list_operator?("in")
true

iex> FlopRest.Operators.list_operator?("gte")
false

to_flop(operator)

@spec to_flop(String.t()) :: String.t()

Converts a REST operator string to the corresponding Flop operator.

Known operators are mapped (e.g., "gte" → ">="). Unknown operators are passed through verbatim for Flop to validate.

Examples

iex> FlopRest.Operators.to_flop("gte")
">="

iex> FlopRest.Operators.to_flop("unknown")
"unknown"

to_rest(flop_op)

@spec to_rest(atom()) :: String.t() | nil

Converts a Flop operator atom to the corresponding REST operator string.

Returns nil for equality operator (:==) since equality filters use bare values without an operator suffix in REST style.

Unknown operators are passed through as strings.

Examples

iex> FlopRest.Operators.to_rest(:>=)
"gte"

iex> FlopRest.Operators.to_rest(:==)
nil

iex> FlopRest.Operators.to_rest(:unknown)
"unknown"