superchris
Read action that does a contains search
I’m sure this must be a trivial thing to do, but in looking through the documentation so far I have not figured this out. I’m trying to make a simple read action that does a substring search and the syntax is just not clear to me. Feel free to RTFM me, but please point me to the right place in the docs ![]()
Here’s what I’ve tried:
read :query do
argument :query, :string, allow_nil?: false
filter expr(contains(name, ^arg[:query]))
end
This fails compilation with undefined function contains/2 (there is no such import)
Marked As Solved
superchris
Yup, this was it! Derp. I need to pair more ![]()
The contains thing was weird though. I swear I copied that from the terminal, but when I put the code back to what I had, now I get much more helpful error about undefined variable arg. At least that probably would have pointed me in the right direction.
For posterity, this worked like a champ:
read :query do
argument :query, :string, allow_nil?: false
filter expr(contains(string_downcase(name), string_downcase(^arg(:query))))
end
I’m sure this can be cleaned up a little, but in case someone stumbles upon this looking for the example I was looking for its a start.
Popular in Questions
Other popular topics
Latest Ash Threads
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security










