ContextKit.Query (ContextKit v0.4.0)
View SourceProvides dynamic query building functionality with extensive filtering operations for Ecto queries.
This module is core to ContextKit's filtering capabilities, providing a flexible way to build complex database queries from runtime parameters.
Query Building
The query building process consists of:
- Creating a base query with proper binding names
- Applying field filters based on schema fields
- Applying standard query options (order_by, limit, etc.)
- Applying custom query options
Field Filters
Supports an extensive set of filter operations through a standardized filter syntax:
%{field: field_name, op: operator, value: value}
Available Operators
Basic Comparison:
:==
- Equality:!=
- Inequality:<
- Less than:<=
- Less than or equal:>
- Greater than:>=
- Greater than or equal
Null Checks:
:empty
- Check if field is NULL:not_empty
- Check if field is NOT NULL
List Operations:
:in
- Check if field value is in list:not_in
- Check if field value is not in list:contains
- Check if list field contains value:not_contains
- Check if list field does not contain value
Pattern Matching:
:like
- Case-sensitive pattern matching:not_like
- Negative case-sensitive pattern matching:ilike
- Case-insensitive pattern matching:not_ilike
- Negative case-insensitive pattern matching:=~
- Shorthand for:ilike
Multiple Pattern Matching:
:like_and
- All patterns must match (case-sensitive):like_or
- Any pattern must match (case-sensitive):ilike_and
- All patterns must match (case-insensitive):ilike_or
- Any pattern must match (case-insensitive)
Standard Query Options
The following standard query options are supported:
:order_by
- Specify sort order:group_by
- Group results:limit
- Limit number of results:preload
- Preload associations:paginate
- Enable pagination with optional configuration