Query building functions for AshScylla data layer.
Provides optimized query building with filter-to-CQL conversion, prepared statement support, and token-based pagination.
Secondary Index Support
When filtering on non-primary key columns, this module checks if a secondary index exists and generates appropriate CQL. ScyllaDB/Cassandra can use secondary indexes for equality checks (=) but not for range queries.
Summary
Functions
Builds an optimized CQL query from the data layer query struct.
Builds ORDER BY clause from sort items.
Builds WHERE clause from Ash filters.
Checks if a filter can use secondary indexes.
Converts Ash filter expressions to CQL (safe version).
Converts Ash filter expressions to CQL (bang version).
Functions
@spec build_optimized_query(AshScylla.DataLayer.t()) :: {String.t(), list()}
Builds an optimized CQL query from the data layer query struct.
If filters are on columns with secondary indexes, the query will use those indexes automatically.
Builds ORDER BY clause from sort items.
Sort items can be:
- Maps with
:fieldand:directionkeys - Tuples like
{field, direction}(Ash standard format)
Builds WHERE clause from Ash filters.
Checks if a filter can use secondary indexes.
Returns {:ok, indexed_columns} if the filter can use indexes,
or {:error, reason} if it cannot.
Converts Ash filter expressions to CQL (safe version).
Returns {cql, params} on success or {:error, {:unknown_filter, term()}} on failure.
Converts Ash filter expressions to CQL (bang version).
Raises ArgumentError on unknown filter expressions.