FatEcto.Query.OperatorApplier (FatEcto v1.3.0)
View SourceProvides helper functions to apply dynamic query operators for Ecto queries.
This module centralizes the logic for applying various query operators such as $LIKE, $ILIKE, $LT, $GT, etc.,
as well as their negated counterparts (e.g., $NOT_LIKE, $NOT_ILIKE). It is designed to work with FatDynamics and
FatNotDynamics modules to generate dynamic Ecto query conditions.
Supported Operators
Positive Operators
$LIKE: Matches a pattern in a string.$NOT_LIKE: Excludes rows that match a pattern in a string.$ILIKE: Case-insensitive match of a pattern in a string.$NOT_ILIKE: Case-insensitive exclusion of rows that match a pattern in a string.$NULL: Matches rows where the field is null.$NOT_NULL: Matches rows where the field is not null.$CAST_TO_DATE_EQUAL: Casts field to date and matches a specific date value.$CAST_TO_DATE_NOT_EQUAL: Casts field to date and excludes a specific date value.$CAST_TO_DATE_GTE: Casts field to date and matches dates greater than or equal to a value.$CAST_TO_DATE_GT: Casts field to date and matches dates greater than a value.$CAST_TO_DATE_LT: Casts field to date and matches dates less than a value.$CAST_TO_DATE_LTE: Casts field to date and matches dates less than or equal to a value.$LT: Less than.$LTE: Less than or equal to.$GT: Greater than.$GTE: Greater than or equal to.$BETWEEN: Matches values between a range (exclusive).$BETWEEN_EQUAL: Matches values between a range (inclusive).$NOT_BETWEEN: Excludes values between a range (exclusive).$NOT_BETWEEN_EQUAL: Excludes values between a range (inclusive).$IN: Matches values in a list.$NOT_IN: Excludes values in a list.$EQUAL: Matches a specific value.$NOT_EQUAL: Excludes a specific value.
Negated Operators (for $NOT conditions)
$LIKE: Negates the$LIKEcondition.$ILIKE: Negates the$ILIKEcondition.$LT: Negates the$LTcondition.$LTE: Negates the$LTEcondition.$GT: Negates the$GTcondition.$GTE: Negates the$GTEcondition.$EQUAL: Negates the$EQUALcondition.
Usage
This module is typically used internally by FatEcto.FatQuery.FatWhere and FatEcto.FatQuery.WhereOr to construct
dynamic queries. It abstracts away the complexity of applying operators and ensures consistency across the codebase.
Example
# Applying a `$LIKE` operator
OperatorApplier.apply_operator("$LIKE", :name, "%John%", [])
# Applying a negated `$EQUAL` operator
OperatorApplier.apply_not_condition("$EQUAL", :age, 30, [])
Summary
Functions
@spec allowed_not_operators() :: [String.t(), ...]
@spec allowed_operators() :: [String.t(), ...]
@spec apply_nil_operator(String.t(), atom()) :: nil | Ecto.Query.dynamic_expr()
@spec apply_not_condition(String.t(), atom(), any()) :: nil | Ecto.Query.dynamic_expr()
@spec apply_operator(String.t(), atom(), any()) :: nil | Ecto.Query.dynamic_expr()