I am building an API for querying spatio-temporal data and for filtering / sorting I chose to use Flop since it does most of what I need out of the box and most of what it doesn’t do out of the box, I can implement using custom_fields.
However, I don’t seem to get how to define new operators in custom_field’s. For example, I’d like to define Postgres’s range operators (<@
, >@
, &&
, etc.) to use them in filters, but as soon as I try, it throws me an error and lists me the built-in operators.
For example, this doesn’t work:
@derive {
Flop.Schema,
filterable: [:id, :year_range],
sortable: [:id],
adapter_opts: [
custom_fields: [
year_range: [
filter: {CustomFlopFilters, :year_range_filter, [source: :year]},
ecto_type: Int4Range,
operators: [:&&] # <-- Here is the problem
]
]
]
}
Of course, I managed to get everything working by semantically abusing the built-in operators, e.g.:
@derive {
Flop.Schema,
filterable: [:id, :year_range],
sortable: [:id],
adapter_opts: [
custom_fields: [
year_range: [
filter: {CustomFlopFilters, :year_range_filter, [source: :year]},
ecto_type: Int4Range,
operators: [:=~]
]
]
]
}
But there comes a point where you need to define new ones, or maybe you prefer to use a notation that makes sense to you.
Any suggestions on how to proceed?