FatEcto.Dynamics.FatOperatorHelper (FatEcto v1.1.0)

View Source

Provides 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
FatOperatorHelper.apply_operator("$LIKE", :name, "%John%", [])

# Applying a negated `$EQUAL` operator
FatOperatorHelper.apply_not_condition("$EQUAL", :age, 30, [])

Summary

Functions

allowed_not_operators()

@spec allowed_not_operators() :: [String.t(), ...]

allowed_operators()

@spec allowed_operators() :: [String.t(), ...]

apply_nil_operator(binary, field, opts)

@spec apply_nil_operator(String.t(), atom(), Keyword.t()) ::
  nil | Ecto.Query.dynamic_expr()

apply_not_condition(arg1, field, value, opts)

@spec apply_not_condition(String.t(), atom(), any(), Keyword.t()) ::
  nil | Ecto.Query.dynamic_expr()

apply_operator(arg1, field, value, opts)

@spec apply_operator(String.t(), atom(), any(), Keyword.t()) ::
  nil | Ecto.Query.dynamic_expr()