Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement missing FilterBuilder functions #12

Merged
merged 1 commit into from
Dec 31, 2024

Conversation

zoedsoupe
Copy link
Collaborator

@zoedsoupe zoedsoupe commented Dec 31, 2024

Problem

The original implementation of logical and filtering functions in the FilterBuilder module used names (and, or, in, not) that conflicted with Elixir’s reserved keywords. Additionally, the existing functions lacked support for a more user-friendly DSL to represent conditions, making the API less intuitive and prone to errors when constructing complex queries with PostgREST.

Solution

  • Renamed Functions:
  • and/2 to all_of/2
  • or/2 to any_of/2
  • in/2 to within/2
  • not/3 to negate/3

These changes avoid conflicts with Elixir’s reserved keywords while keeping the naming clear and aligned with their functionality.

  • Implemented a Custom DSL:
  • Introduced a simpler, declarative syntax for representing conditions to be used with all_of, any_of, and other logical filtering functions.
  • Support for nested conditions (e.g., {:or, [...]}, {:and, [...]}).
  • Added support for any and all modifiers in conditions (e.g., tags=like(any).{elixir,phoenix}).
  • Refactored process_condition/1:
  • Improved readability and modularity by splitting complex logic into helper functions.
  • Added validation for supported operators to ensure safety and robustness.

Rationale

The renaming of functions resolves naming conflicts with Elixir’s core Kernel functions, improving the library’s compatibility and usability in pipelines.

The custom DSL aligns with Elixir’s declarative and functional programming principles, making it easier to construct and manage complex query conditions. This approach reduces the risk of errors caused by manually crafting PostgREST-compatible syntax strings and ensures consistency across the API.

This PR also addresses issue #8 by providing a more intuitive and extensible API for constructing filters and logical operations.

also implement a custom and simpler DSL
to represent conditions to be used in
`any_of`, `all_of` functions

renamed:
- `and/2` to `all_of/2`
- `or/2` to `any_of/2`
- `in/2` to `within/2`
- `not/3` to `negate/3`

to avoid conflict with [Kernel](https://hexdocs.pm/elixir/Kernel.html)
@zoedsoupe zoedsoupe merged commit 01fa19b into main Dec 31, 2024
1 check passed
@zoedsoupe zoedsoupe deleted the feat/missing-filter-functions branch December 31, 2024 01:15
@zoedsoupe zoedsoupe linked an issue Dec 31, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement missing functions for FilterBuilder
1 participant