Arex.Query (arex v0.1.0)

Copy Markdown View Source

Read-oriented query helpers.

Arex.Query is the lowest-friction way to execute read statements without dropping all the way to Arex.Http. It keeps option resolution, normalized error handling, and paging behavior aligned with the rest of the library.

Use sql/3 for ordinary ArcadeDB SQL queries and run/3 when you want the query language to come from call options or application config.

Arex.Query is statement-oriented. It does not infer record types or append tenant and scope predicates automatically. If you want type-aware or boundary-aware CRUD semantics, prefer Arex.Record.

Summary

Functions

Returns the first row from a paged query or nil when the query is empty.

Returns exactly one row or nil.

Returns one page of rows using ArcadeDB skip and limit semantics.

Executes a raw query using the resolved query language.

Streams query pages until there are no more rows.

Functions

first(statement, params \\ %{}, opts \\ [])

Returns the first row from a paged query or nil when the query is empty.

Internally this delegates to page/3 with limit: 1.

one(statement, params \\ %{}, opts \\ [])

Returns exactly one row or nil.

When the query returns more than one row, the function fails with a normalized :multiple_results error.

page(statement, params \\ %{}, opts \\ [])

Returns one page of rows using ArcadeDB skip and limit semantics.

The returned map contains :entries, :limit, :offset, :count, and :has_more?. Arex fetches one extra row internally so it can answer the has_more? question without requiring a separate count query.

run(statement, params \\ %{}, opts \\ [])

Executes a raw query using the resolved query language.

language comes from call options, application config, or the default "sql". This helper is useful when you want Arex to honor the resolved language instead of forcing SQL.

sql(statement, params \\ %{}, opts \\ [])

Executes a SQL query.

This helper always forces language: "sql" regardless of any configured default language.

stream_pages(statement, params \\ %{}, opts \\ [])

Streams query pages until there are no more rows.

The stream yields {:ok, page_map} tuples and stops at the first error, which is yielded as {:error, error_map}.