FatEcto.Query.OperatorApplier (FatEcto v1.2.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.$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$LIKE
condition.$ILIKE
: Negates the$ILIKE
condition.$LT
: Negates the$LT
condition.$LTE
: Negates the$LTE
condition.$GT
: Negates the$GT
condition.$GTE
: Negates the$GTE
condition.$EQUAL
: Negates the$EQUAL
condition.
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()