superchris

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 :slight_smile:

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

superchris

Yup, this was it! Derp. I need to pair more :wink:

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.

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement