spagyther
How do I define new operators in Flop's custom_field?
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?
Most Liked
spagyther
Great, I’ll first implement a couple new ops and if everything works out fine, I’ll try to figure out how to generalize the process.
egze
Ping me if you want to join forces. I would also love to have custom operators.
woylie
It’s currently not possible to define custom operators. You’ll have to use one of the existing ones, as you did.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








