spagyther
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?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
woylie
It’s currently not possible to define custom operators. You’ll have to use one of the existing ones, as you did.
spagyther
Thank you for the answer (and for the great library too), I was afraid of that.
Are there plans of making it possible or I would be better off with forking Flop and implementing the ops myself?
woylie
I don’t have plans working on that myself at the moment, but I’m open to a proposal/PR.
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.