Is it possible to do something like this in Elixir?
def build_query(query, "name", name != "", _conn) do
Ecto.Query.where(query, [p], p.name == ^name)
end
Is it possible to do something like this in Elixir?
def build_query(query, "name", name != "", _conn) do
Ecto.Query.where(query, [p], p.name == ^name)
end
def build_query(query, "name", name, _conn) when name != "" do
Ecto.Query.where(query, [p], p.name == ^name)
end
However, I would consider filtering out this kind of thing at a layer closer to the input and not worrying about it later on when building the query.
You mean on the UI front-end? Not sending parameter name
if it is empty?
That’s one option, or at the controller layer, or whatever bit of code first touches the params.