Mq.Query (mq_elixir v0.1.22)
View SourceProgrammatic query builder for constructing mq queries.
Queries are built by starting with a selector (e.g. h2/0, code/0) and
chaining operations via the |> pipe operator. The resulting struct can be
passed directly to Mq.run/3 or converted to its string form with
to_string/1 / Kernel.to_string/1.
Basic usage
iex> Mq.Query.h2() |> to_string()
".h2"
iex> Mq.Query.h2() |> Mq.Query.to_text() |> to_string()
".h2 | to_text()"Filters
Use Mq.Filter to build filter expressions for select/2 and map/2:
iex> alias Mq.{Query, Filter}
iex> Query.h2() |> Query.select(Filter.contains("Feature")) |> to_string()
".h2 | select(contains(\"Feature\"))"Combined filters
iex> alias Mq.{Query, Filter}
iex> query = Query.h2()
...> |> Query.select(
...> Filter.contains("API")
...> |> Filter.and_filter(Filter.negate(Filter.contains("Internal")))
...> )
...> |> Query.to_text()
...> |> Query.downcase()
iex> to_string(query)
".h2 | select(contains(\"API\") and not(contains(\"Internal\"))) | to_text() | downcase()"Using with Mq.run/3
iex> {:ok, result} = Mq.run(Mq.Query.h2(), "# Hello\n## World")
iex> result.values
["## World"]
Summary
Functions
Absolute value.
Add/concatenate other to the current value.
Standalone .align attribute selector.
Access the .align attribute.
Standalone .alt attribute selector.
Access the .alt attribute.
Get the attribute named name.
Base64-encode.
Base64-decode.
Base64url-encode.
Base64url-decode.
Return the basename of a path.
Select all blockquotes.
Capture groups from pattern (regex).
Ceiling.
Standalone .checked attribute selector.
Access the .checked attribute (task list).
Descend into children.
Return default when the current value is none/null.
Select all code blocks.
Select all inline code spans.
Standalone .column attribute selector.
Access the .column attribute.
Remove nil/null entries.
Emit debug information for the current value.
Select all link definition nodes.
Delete the element value.
Select all strikethrough (delete) nodes.
Standalone .depth attribute selector.
Access the .depth attribute.
Return the directory part of a path.
Select all checked task list items.
Convert to lowercase (Unicode-aware).
Select all emphasis (italic) nodes.
Check whether the current value is empty.
Return the key-value entries of a dict.
Exponential (e^x).
Explode a string into codepoints.
Return the file extension.
Standalone .fence attribute selector.
Access the .fence attribute.
Return the first element.
Flatten nested arrays.
Floor.
Select all footnote definition nodes.
Select all footnote reference nodes.
Decode from hex.
Get the value at dict key key.
Get the title of a link or image.
Get the URL of a link or image.
Replace all occurrences of pattern with replacement (regex).
Select all h1 headings.
Select all h2 headings.
Select all h3 headings.
Select all h4 headings.
Select all h5 headings.
Select all h6 headings.
Select all headings (any level).
Select all horizontal rules.
Select all raw HTML nodes.
Access the .ident attribute.
Select all images.
Select all image reference nodes.
Implode codepoints back into a string.
Find the first index of value.
Insert val at index idx.
Intern the current string.
Access the .index attribute (item index in a list).
Join elements with sep.
Return the keys of a dict.
Access the .label attribute.
Standalone .lang attribute selector.
Access the .lang attribute (e.g. code block language).
Return the last element.
Return the byte length of the current value.
Return the length of the current value.
Standalone .level attribute selector.
Access the .level attribute.
Limit output to n elements.
Select all line break nodes.
Select all links.
Select all link reference nodes.
Select all list items.
Select the list item at index n.
Natural logarithm.
Base-10 logarithm.
Trim leading whitespace.
Append a map(filter) step.
Select all math blocks.
Select all inline math spans.
Return the larger of the current value and other.
MD5 hash.
Select all MDX flow expression nodes.
Select all MDX JS/ESM import/export nodes.
Select all MDX JSX flow elements.
Select all MDX JSX text elements.
Access the .name attribute (MDX element name).
Select all MDX text expression nodes.
Standalone .meta attribute selector.
Access the .meta attribute.
Return the smaller of the current value and other.
Check whether the current value is NaN.
Negate the current numeric value.
Standalone .values attribute selector.
Select the nth element (0-based).
Standalone .ordered attribute selector.
Access the .ordered attribute.
Select all paragraphs.
Join the current path with other.
Pipe two queries together.
Raise the current value to the power of n.
Standalone dict property selector: ."key".
Access a dict property by key (generates ."key").
Take a range of n elements.
Recursive / deep selector — descend into all children.
Repeat the current value n times.
Replace the first occurrence of from with to.
Reverse the current value.
Find the last index of value.
Round.
Standalone .row attribute selector.
Access the .row attribute.
Trim trailing whitespace.
Standalone select(filter) — no leading selector.
Append a select(filter) step.
Set dict key key to val.
Set the attribute named name to val.
Set the checked state of a task list item.
Set the language of a code block.
Set whether a list is ordered.
Set the reference identifier of a link ref or image ref.
SHA-256 hash.
SHA-512 hash.
Slice elements from start to stop.
Sort the current value.
Split the current value by sep.
Square root.
Return the filename stem (basename without extension).
Convert to a string value (mq to_string() function).
Select all strong (bold) nodes.
Select all tables.
Select all table alignment nodes.
Select the table cell at row r, column c.
Select all cells in table column n.
Select all cells in table row n.
Select all task list items.
Test whether the current value matches pattern (regex).
Select all text nodes.
Access the .title attribute.
Convert to an array value.
Convert to bytes.
Convert to a fenced code block.
Convert to an inline code span.
Convert to an emphasis (italic) node.
Convert to a heading of the given depth (1–6).
Encode to hex.
Convert to a horizontal rule.
Convert to HTML.
Convert to an image node.
Convert to a link node.
Convert to Markdown.
Convert to a Markdown string (serialized).
Convert to a math block.
Convert to an inline math span.
Convert to a list item at nesting list_level.
Convert to a Markdown element with the given node node_name.
Build a table cell with content at row r, column c.
Build a table row from the given cells list.
Convert to a plain Markdown text node.
Convert to MDX.
Convert to a number value.
Return the raw mq query string.
Convert to a strong (bold) node.
Convert to plain text.
Select all unchecked task list items.
Select all TOML front matter nodes.
Trim leading and trailing whitespace.
Truncate.
Return the type of the current value.
Remove duplicate entries.
Convert to uppercase (Unicode-aware).
Update the node content to content.
Standalone .url attribute selector.
Access the .url attribute.
URL-encode the current value.
Return the UTF-8 byte length of the current value.
Standalone .value attribute selector.
Access the .value attribute of the selected node.
Return the values of a dict.
Select all YAML front matter nodes.
Types
@type t() :: %Mq.Query{expr: String.t()}
Functions
Absolute value.
Add/concatenate other to the current value.
Standalone .align attribute selector.
Access the .align attribute.
Standalone .alt attribute selector.
Access the .alt attribute.
Get the attribute named name.
Base64-encode.
Base64-decode.
Base64url-encode.
Base64url-decode.
Return the basename of a path.
Select all blockquotes.
Capture groups from pattern (regex).
Ceiling.
Standalone .checked attribute selector.
Access the .checked attribute (task list).
Descend into children.
Return default when the current value is none/null.
Select all code blocks.
Select all inline code spans.
Standalone .column attribute selector.
Access the .column attribute.
Remove nil/null entries.
Emit debug information for the current value.
Select all link definition nodes.
Delete the element value.
Select all strikethrough (delete) nodes.
Standalone .depth attribute selector.
Access the .depth attribute.
Return the directory part of a path.
Select all checked task list items.
Convert to lowercase (Unicode-aware).
Select all emphasis (italic) nodes.
Check whether the current value is empty.
Return the key-value entries of a dict.
Exponential (e^x).
Explode a string into codepoints.
Return the file extension.
Standalone .fence attribute selector.
Access the .fence attribute.
Return the first element.
Flatten nested arrays.
Floor.
Select all footnote definition nodes.
Select all footnote reference nodes.
Decode from hex.
Get the value at dict key key.
Get the title of a link or image.
Get the URL of a link or image.
Replace all occurrences of pattern with replacement (regex).
Select all h1 headings.
Select all h2 headings.
Select all h3 headings.
Select all h4 headings.
Select all h5 headings.
Select all h6 headings.
Select all headings (any level).
Select all horizontal rules.
Select all raw HTML nodes.
Access the .ident attribute.
Select all images.
Select all image reference nodes.
Implode codepoints back into a string.
Find the first index of value.
Insert val at index idx.
Intern the current string.
Access the .index attribute (item index in a list).
Join elements with sep.
Return the keys of a dict.
Access the .label attribute.
Standalone .lang attribute selector.
Access the .lang attribute (e.g. code block language).
Return the last element.
Return the byte length of the current value.
Return the length of the current value.
Standalone .level attribute selector.
Access the .level attribute.
Limit output to n elements.
Select all line break nodes.
Select all links.
Select all link reference nodes.
Select all list items.
Select the list item at index n.
Natural logarithm.
Base-10 logarithm.
Trim leading whitespace.
Append a map(filter) step.
Select all math blocks.
Select all inline math spans.
Return the larger of the current value and other.
MD5 hash.
Select all MDX flow expression nodes.
Select all MDX JS/ESM import/export nodes.
Select all MDX JSX flow elements.
Select all MDX JSX text elements.
Access the .name attribute (MDX element name).
Select all MDX text expression nodes.
Standalone .meta attribute selector.
Access the .meta attribute.
Return the smaller of the current value and other.
Check whether the current value is NaN.
Negate the current numeric value.
Standalone .values attribute selector.
Select the nth element (0-based).
Standalone .ordered attribute selector.
Access the .ordered attribute.
Select all paragraphs.
Join the current path with other.
Pipe two queries together.
Query.h2() |> Query.pipe(Query.to_text())
# => ".h2 | to_text()"
Raise the current value to the power of n.
Standalone dict property selector: ."key".
Access a dict property by key (generates ."key").
Take a range of n elements.
Recursive / deep selector — descend into all children.
Repeat the current value n times.
Replace the first occurrence of from with to.
Reverse the current value.
Find the last index of value.
Round.
Standalone .row attribute selector.
Access the .row attribute.
Trim trailing whitespace.
Standalone select(filter) — no leading selector.
Query.select(Filter.mdx?())
# => "select(is_mdx())"
Append a select(filter) step.
Set dict key key to val.
Set the attribute named name to val.
Set the checked state of a task list item.
Set the language of a code block.
Set whether a list is ordered.
Set the reference identifier of a link ref or image ref.
SHA-256 hash.
SHA-512 hash.
Slice elements from start to stop.
Sort the current value.
Split the current value by sep.
Square root.
Return the filename stem (basename without extension).
Convert to a string value (mq to_string() function).
Select all strong (bold) nodes.
Select all tables.
Select all table alignment nodes.
Select the table cell at row r, column c.
Select all cells in table column n.
Select all cells in table row n.
Select all task list items.
Test whether the current value matches pattern (regex).
Select all text nodes.
Access the .title attribute.
Convert to an array value.
Convert to bytes.
Convert to a fenced code block.
to_code(q)— no language (null)to_code(q, "elixir")— with language
Convert to an inline code span.
Convert to an emphasis (italic) node.
Convert to a heading of the given depth (1–6).
Encode to hex.
Convert to a horizontal rule.
Convert to HTML.
Convert to an image node.
to_image(q, url)— current value becomes the alt textto_image(q, url, alt)— explicit alt, empty titleto_image(q, url, alt, title)— explicit alt and title
Convert to a link node.
to_link(q, url)— current value becomes the link textto_link(q, url, text)— explicit text, empty titleto_link(q, url, text, title)— explicit text and title
Convert to Markdown.
Convert to a Markdown string (serialized).
Convert to a math block.
Convert to an inline math span.
Convert to a list item at nesting list_level.
Convert to a Markdown element with the given node node_name.
Build a table cell with content at row r, column c.
Build a table row from the given cells list.
Convert to a plain Markdown text node.
Convert to MDX.
Convert to a number value.
Return the raw mq query string.
Convert to a strong (bold) node.
Convert to plain text.
Select all unchecked task list items.
Select all TOML front matter nodes.
Trim leading and trailing whitespace.
Truncate.
Return the type of the current value.
Remove duplicate entries.
Convert to uppercase (Unicode-aware).
Update the node content to content.
Standalone .url attribute selector.
Access the .url attribute.
URL-encode the current value.
Return the UTF-8 byte length of the current value.
Standalone .value attribute selector.
Access the .value attribute of the selected node.
Return the values of a dict.
Select all YAML front matter nodes.