Mq.Filter (mq_elixir v0.1.22)

View Source

Filter expressions for use inside select() and map() in mq queries.

Filters are constructed by calling the functions in this module. They can be combined with and_filter/2, or_filter/2, and negate/1, and work naturally with the |> pipe operator.

Examples

iex> Mq.Filter.contains("Feature")
#Mq.Filter<contains("Feature")>

iex> Mq.Filter.contains("Feature") |> Mq.Filter.and_filter(Mq.Filter.starts_with("##")) |> to_string()
"contains(\"Feature\") and starts_with(\"##\")"

iex> Mq.Filter.all([Mq.Filter.contains("API"), Mq.Filter.ne("## Draft")])
#Mq.Filter<contains("API") and ne("## Draft")>

Use filters with Mq.Query.select/2:

iex> alias Mq.{Query, Filter}
iex> Query.h2() |> Query.select(Filter.contains("Feature")) |> to_string()
".h2 | select(contains(\"Feature\"))"

Summary

Functions

Add/concatenate other to the current value.

Combine a list of filters with AND (all must match).

Combine two filters with boolean AND (&&).

Combine a list of filters with OR (any must match).

Match nodes whose text contains text.

Match empty nodes.

Match nodes whose text ends with text.

Match nodes equal to value.

Match nodes greater than value.

Match nodes greater than or equal to value.

The length of the current value.

Match nodes less than value.

Match nodes less than or equal to value.

Match MDX nodes.

Match nodes whose numeric value is NaN.

Match nodes not equal to value.

Negate a filter with not(...).

Match nodes with no value (none/null).

Match nodes whose text does not match the regex pattern.

Combine two filters with boolean OR.

Match nodes whose text matches the regex pattern.

Match nodes whose text starts with text.

Match nodes whose text matches the regex pattern.

Return the raw filter expression string.

Trim whitespace from the current value.

Filter by the node type string.

Types

t()

@type t() :: %Mq.Filter{expr: String.t()}

Functions

add(other)

Add/concatenate other to the current value.

all(list)

Combine a list of filters with AND (all must match).

Filter.all([Filter.contains("API"), Filter.ne("## Draft"), Filter.starts_with("## ")])

and_filter(filter1, filter2)

Combine two filters with boolean AND (&&).

Works naturally with |>:

Filter.contains("API") |> Filter.and_filter(Filter.ne("## Draft"))

any(list)

Combine a list of filters with OR (any must match).

Filter.any([Filter.contains("A"), Filter.contains("B")])

contains(text)

Match nodes whose text contains text.

empty()

Match empty nodes.

ends_with(text)

Match nodes whose text ends with text.

eq(value)

Match nodes equal to value.

gt(value)

Match nodes greater than value.

gte(value)

Match nodes greater than or equal to value.

length()

The length of the current value.

lt(value)

Match nodes less than value.

lte(value)

Match nodes less than or equal to value.

mdx?()

Match MDX nodes.

nan?()

Match nodes whose numeric value is NaN.

ne(value)

Match nodes not equal to value.

negate(filter)

Negate a filter with not(...).

Filter.negate(Filter.contains("draft"))
# => not(contains("draft"))

none?()

Match nodes with no value (none/null).

not_regex_match?(pattern)

Match nodes whose text does not match the regex pattern.

or_filter(filter1, filter2)

Combine two filters with boolean OR.

Works naturally with |>:

Filter.contains("A") |> Filter.or_filter(Filter.contains("B"))

regex_match?(pattern)

Match nodes whose text matches the regex pattern.

starts_with(text)

Match nodes whose text starts with text.

test(pattern)

Match nodes whose text matches the regex pattern.

to_filter_string(filter)

Return the raw filter expression string.

trim()

Trim whitespace from the current value.

type()

Filter by the node type string.