fireproofsocks

fireproofsocks

Dynamic Queries in Ecto

I have once again nose-dived into the treeline while attempting to follow the official docs… I’m trying to stay positive here, but I am really feeling malnourished when it comes to nutritious examples. I would love some help clarifying the mystery presented on Ecto.Query — Ecto v3.14.0

dynamic = false

dynamic =
  if params["is_public"] do
    dynamic([p], p.is_public or ^dynamic)
  else
    dynamic
  end

dynamic =
  if params["allow_reviewers"] do
    dynamic([p, a], a.reviewer == true or ^dynamic)
  else
    dynamic
  end

from query, where: ^dynamic
  1. First off, how might we actually pass in a value from the parameters into the where condition? The examples conveniently sidesteps that critical use-case. Like what if you want to filter a list of posts by the author? Would that be something like this?

    dynamic =
    if params[“author”] do
    dynamic([p], p.author = params[“author”] or ^dynamic)
    else
    dynamic
    end

  2. What’s up with the or and and in these? If I assume all the filtering parameters I provide must be fulfilled, doesn’t that mean that I should always use “and”? What’s up with this or ^dynamic? Can someone explain how and/or affects this and can someone explain this bizarre syntax? The only toe-hold my brain can get on this at present comes from some old-school query-string concatenation where the select criteria would be WHERE 1 – then each subsequent clause could always begin with “AND condition=something”. Is that what’s going on?

  3. What’s up with the naked from query, where: ^dynamic ? What’s going on there? How can I actually use that in a query? I’m used to seeing something like query = from p in Post – I don’t understand that at all, really, but at least it’s pervasive throughout the Ecto Query docs.

  4. How do we use this in a query that involves a join? It seems that it trips over the “where” clause that defines the join?

If I can get some help wrapping my head around this I can put together a PR that provides some examples that are easier to follow. Thanks for any guidance!

Most Liked

fireproofsocks

fireproofsocks

Sorry, you’re right: there’s nothing positive in commentary like that. I apologize. I was writing from a point of extreme frustration and exhaustion. I would like to submit some examples once I can get things working.

peerreynders

peerreynders

iex(1)> alias MusicDB.{Repo,Album,Track}
[MusicDB.Repo, MusicDB.Album, MusicDB.Track]
iex(2)> import Ecto.Query
Ecto.Query
iex(3)> dynamic_where = fn (album_id, params) ->
...(3)>   default = dynamic([t], t.album_id == ^album_id)
...(3)>   case params do
...(3)>     %{name: name, value: value, op: :gt} ->
...(3)>       dynamic([t], field(t, ^name) > ^value and ^default)
...(3)>     %{name: name, value: value} ->
...(3)>       dynamic([t], field(t, ^name) <= ^value and ^default)
...(3)>     _ ->
...(3)>       default
...(3)>   end
...(3)> end
#Function<12.127694169/2 in :erl_eval.expr/5>
iex(4)> album_id = 2
2
iex(5)> from(t in Track, where: ^dynamic_where.(album_id, %{})) |> Repo.all()

17:49:20.001 [debug] QUERY OK source="tracks" db=2.9ms decode=2.3ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE (t0."album_id" = $1) [2]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1061,
    duration_string: nil,
    id: 10,
    index: 5,
    inserted_at: ~N[2018-06-16 20:29:41.480612],
    number_of_plays: 0,
    title: "No Blues",
    updated_at: ~N[2018-06-16 20:29:41.480618]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 754,
    duration_string: nil,
    id: 9,
    index: 4,
    inserted_at: ~N[2018-06-16 20:29:41.480045],
    number_of_plays: 0,
    title: "Miles",
    updated_at: ~N[2018-06-16 20:29:41.480051]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 896,
    duration_string: nil,
    id: 8,
    index: 3,
    inserted_at: ~N[2018-06-16 20:29:41.479460],
    number_of_plays: 0,
    title: "Walkin'",
    updated_at: ~N[2018-06-16 20:29:41.479465]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 774,
    duration_string: nil,
    id: 7,
    index: 2,
    inserted_at: ~N[2018-06-16 20:29:41.478857],
    number_of_plays: 0,
    title: "Stella By Starlight",
    updated_at: ~N[2018-06-16 20:29:41.478864]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1006,
    duration_string: nil,
    id: 6,
    index: 1,
    inserted_at: ~N[2018-06-16 20:29:41.478296],
    number_of_plays: 0,
    title: "If I Were A Bell",
    updated_at: ~N[2018-06-16 20:29:41.478302]
  }
]
iex(6)> from(t in Track, where: ^dynamic_where.(album_id, %{name: :duration, value: 800})) |> Repo.all()

17:49:20.013 [debug] QUERY OK source="tracks" db=2.0ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE ((t0."duration" <= $1) AND (t0."album_id" = $2)) [800, 2]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 754,
    duration_string: nil,
    id: 9,
    index: 4,
    inserted_at: ~N[2018-06-16 20:29:41.480045],
    number_of_plays: 0,
    title: "Miles",
    updated_at: ~N[2018-06-16 20:29:41.480051]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 774,
    duration_string: nil,
    id: 7,
    index: 2,
    inserted_at: ~N[2018-06-16 20:29:41.478857],
    number_of_plays: 0,
    title: "Stella By Starlight",
    updated_at: ~N[2018-06-16 20:29:41.478864] 
  }
]
iex(7)> from(t in Track, where: ^dynamic_where.(album_id, %{name: :duration, value: 800, op: :gt})) |> Repo.all()

17:49:20.016 [debug] QUERY OK source="tracks" db=1.8ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE ((t0."duration" > $1) AND (t0."album_id" = $2)) [800, 2]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1061,
    duration_string: nil,
    id: 10,
    index: 5,
    inserted_at: ~N[2018-06-16 20:29:41.480612],
    number_of_plays: 0,
    title: "No Blues",
    updated_at: ~N[2018-06-16 20:29:41.480618]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 896,
    duration_string: nil,
    id: 8,
    index: 3,
    inserted_at: ~N[2018-06-16 20:29:41.479460],
    number_of_plays: 0,
    title: "Walkin'",
    updated_at: ~N[2018-06-16 20:29:41.479465]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1006,
    duration_string: nil,
    id: 6,
    index: 1,
    inserted_at: ~N[2018-06-16 20:29:41.478296],
    number_of_plays: 0,
    title: "If I Were A Bell",
    updated_at: ~N[2018-06-16 20:29:41.478302]
  }
] 
iex(8)> 

Though frankly:

iex(1)> alias MusicDB.{Repo,Album,Track}
[MusicDB.Repo, MusicDB.Album, MusicDB.Track]
iex(2)> import Ecto.Query
Ecto.Query
iex(3)> make_where = fn (query, album_id, params) ->
...(3)>   case params do
...(3)>     %{name: name, value: value, op: :gt} ->
...(3)>       from(p in query, where: field(p, ^name) > ^value and p.album_id == ^album_id) 
...(3)>     %{name: name, value: value} ->
...(3)>       from(p in query, where: field(p, ^name) <= ^value and p.album_id == ^album_id) 
...(3)>     _ ->
...(3)>       from(p in query, where: p.album_id == ^album_id) 
...(3)>   end
...(3)> end
#Function<18.127694169/3 in :erl_eval.expr/5>
iex(4)> album_id = 2
2
iex(5)> from(t in Track) |> make_where.(album_id, %{}) |> Repo.all()

18:08:35.201 [debug] QUERY OK source="tracks" db=2.7ms decode=2.0ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE (t0."album_id" = $1) [2]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1061,
    duration_string: nil,
    id: 10,
    index: 5,
    inserted_at: ~N[2018-06-16 20:29:41.480612],
    number_of_plays: 0,
    title: "No Blues",
    updated_at: ~N[2018-06-16 20:29:41.480618]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 754,
    duration_string: nil,
    id: 9,
    index: 4,
    inserted_at: ~N[2018-06-16 20:29:41.480045],
    number_of_plays: 0,
    title: "Miles",
    updated_at: ~N[2018-06-16 20:29:41.480051]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 896,
    duration_string: nil,
    id: 8,
    index: 3,
    inserted_at: ~N[2018-06-16 20:29:41.479460],
    number_of_plays: 0,
    title: "Walkin'",
    updated_at: ~N[2018-06-16 20:29:41.479465]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 774,
    duration_string: nil,
    id: 7,
    index: 2,
    inserted_at: ~N[2018-06-16 20:29:41.478857],
    number_of_plays: 0,
    title: "Stella By Starlight",
    updated_at: ~N[2018-06-16 20:29:41.478864]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1006,
    duration_string: nil,
    id: 6,
    index: 1,
    inserted_at: ~N[2018-06-16 20:29:41.478296],
    number_of_plays: 0,
    title: "If I Were A Bell",
    updated_at: ~N[2018-06-16 20:29:41.478302]
  }
]
iex(6)> from(t in Track) |> make_where.(album_id, %{name: :duration, value: 800}) |> Repo.all()

18:08:35.213 [debug] QUERY OK source="tracks" db=2.0ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE ((t0."duration" <= $1) AND (t0."album_id" = $2)) [800, 2]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 754,
    duration_string: nil,
    id: 9,
    index: 4,
    inserted_at: ~N[2018-06-16 20:29:41.480045],
    number_of_plays: 0,
    title: "Miles",
    updated_at: ~N[2018-06-16 20:29:41.480051]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 774,
    duration_string: nil,
    id: 7,
    index: 2,
    inserted_at: ~N[2018-06-16 20:29:41.478857],
    number_of_plays: 0,
    title: "Stella By Starlight",
    updated_at: ~N[2018-06-16 20:29:41.478864] 
  }
]
iex(7)> from(t in Track) |> make_where.(album_id, %{name: :duration, value: 800, op: :gt}) |> Repo.all()

18:08:35.216 [debug] QUERY OK source="tracks" db=2.1ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE ((t0."duration" > $1) AND (t0."album_id" = $2)) [800, 2]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1061,
    duration_string: nil,
    id: 10,
    index: 5,
    inserted_at: ~N[2018-06-16 20:29:41.480612],
    number_of_plays: 0,
    title: "No Blues",
    updated_at: ~N[2018-06-16 20:29:41.480618]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 896,
    duration_string: nil,
    id: 8,
    index: 3,
    inserted_at: ~N[2018-06-16 20:29:41.479460],
    number_of_plays: 0,
    title: "Walkin'",
    updated_at: ~N[2018-06-16 20:29:41.479465]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1006,
    duration_string: nil,
    id: 6,
    index: 1,
    inserted_at: ~N[2018-06-16 20:29:41.478296],
    number_of_plays: 0,
    title: "If I Were A Bell",
    updated_at: ~N[2018-06-16 20:29:41.478302]
  }
] 
iex(8)> 

Ecto queries are composable. Ecto.Query.dynamic/2 comes in handy when you need your where conditions to be composable.

Conditions are composed with and or or:

  • when you compose with or and you don’t need the condition, you default to false instead.
  • when you compose with and and you don’t need the condition, you default to true instead.

Furthermore if you are simply anding the conditions you need, you probably don’t need Ecto.Query.dynamic/2:

iex(1)> alias MusicDB.{Repo,Album,Track}
[MusicDB.Repo, MusicDB.Album, MusicDB.Track]
iex(2)> import Ecto.Query
Ecto.Query
iex(3)> make_where = fn (query, album_id, params) ->
...(3)>   default = from(q in query, where: q.album_id == ^album_id)
...(3)>   case params do
...(3)>     %{name: name, value: value, op: :gt} ->
...(3)>       from(p in default, where: field(p, ^name) > ^value) 
...(3)>     %{name: name, value: value} ->
...(3)>       from(p in default, where: field(p, ^name) <= ^value) 
...(3)>     _ ->
...(3)>       default
...(3)>   end
...(3)> end
#Function<18.127694169/3 in :erl_eval.expr/5>
iex(4)> album_id = 2
2
iex(5)> from(t in Track) |> make_where.(album_id, %{}) |> Repo.all()

18:47:30.295 [debug] QUERY OK source="tracks" db=2.8ms decode=2.2ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE (t0."album_id" = $1) [2]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1061,
    duration_string: nil,
    id: 10,
    index: 5,
    inserted_at: ~N[2018-06-16 20:29:41.480612],
    number_of_plays: 0,
    title: "No Blues",
    updated_at: ~N[2018-06-16 20:29:41.480618]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 754,
    duration_string: nil,
    id: 9,
    index: 4,
    inserted_at: ~N[2018-06-16 20:29:41.480045],
    number_of_plays: 0,
    title: "Miles",
    updated_at: ~N[2018-06-16 20:29:41.480051]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 896,
    duration_string: nil,
    id: 8,
    index: 3,
    inserted_at: ~N[2018-06-16 20:29:41.479460],
    number_of_plays: 0,
    title: "Walkin'",
    updated_at: ~N[2018-06-16 20:29:41.479465]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 774,
    duration_string: nil,
    id: 7,
    index: 2,
    inserted_at: ~N[2018-06-16 20:29:41.478857],
    number_of_plays: 0,
    title: "Stella By Starlight",
    updated_at: ~N[2018-06-16 20:29:41.478864]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1006,
    duration_string: nil,
    id: 6,
    index: 1,
    inserted_at: ~N[2018-06-16 20:29:41.478296],
    number_of_plays: 0,
    title: "If I Were A Bell",
    updated_at: ~N[2018-06-16 20:29:41.478302]
  }
]
iex(6)> from(t in Track) |> make_where.(album_id, %{name: :duration, value: 800}) |> Repo.all()

18:47:30.307 [debug] QUERY OK source="tracks" db=2.0ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE (t0."album_id" = $1) AND (t0."duration" <= $2) [2, 800]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 754,
    duration_string: nil,
    id: 9,
    index: 4,
    inserted_at: ~N[2018-06-16 20:29:41.480045],
    number_of_plays: 0,
    title: "Miles",
    updated_at: ~N[2018-06-16 20:29:41.480051]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 774,
    duration_string: nil,
    id: 7,
    index: 2,
    inserted_at: ~N[2018-06-16 20:29:41.478857],
    number_of_plays: 0,
    title: "Stella By Starlight",
    updated_at: ~N[2018-06-16 20:29:41.478864] 
  }
]
iex(7)> from(t in Track) |> make_where.(album_id, %{name: :duration, value: 800, op: :gt}) |> Repo.all()

18:47:30.311 [debug] QUERY OK source="tracks" db=1.9ms
SELECT t0."id", t0."title", t0."duration", t0."index", t0."number_of_plays", t0."inserted_at", t0."updated_at", t0."album_id" FROM "tracks" AS t0 WHERE (t0."album_id" = $1) AND (t0."duration" > $2) [2, 800]
[
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1061,
    duration_string: nil,
    id: 10,
    index: 5,
    inserted_at: ~N[2018-06-16 20:29:41.480612],
    number_of_plays: 0,
    title: "No Blues",
    updated_at: ~N[2018-06-16 20:29:41.480618]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 896,
    duration_string: nil,
    id: 8,
    index: 3,
    inserted_at: ~N[2018-06-16 20:29:41.479460],
    number_of_plays: 0,
    title: "Walkin'",
    updated_at: ~N[2018-06-16 20:29:41.479465]
  },
  %MusicDB.Track{
    __meta__: #Ecto.Schema.Metadata<:loaded, "tracks">,
    album: #Ecto.Association.NotLoaded<association :album is not loaded>,
    album_id: 2,
    duration: 1006,
    duration_string: nil,
    id: 6,
    index: 1,
    inserted_at: ~N[2018-06-16 20:29:41.478296],
    number_of_plays: 0,
    title: "If I Were A Bell",
    updated_at: ~N[2018-06-16 20:29:41.478302]
  }
] 
iex(8)>

For relatively simple condition composition (more like “chaining” really) with or Ecto.Query.or_where/3 can be used in exactly the same manner.

dynamic/2 becomes necessary when you are composing deeply nested, optional conditions

WHERE
  (... AND ... AND ... AND (... OR (... AND ...)))
  OR (.. AND ((... AND ...) OR ...) AND ...)
  OR (... AND ... AND ...)
  OR ((... OR (... AND ...)) AND ...)
benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I’m not entirely sure what the point of commentary like this is. The Elixir community is still relatively small, and the docs and code that exist are almost always the work of a limited number of people doing the best they can with the time they have available.

That isn’t to say that they’re perfect or even close. I’m confident that you’re right, that the docs could use more examples. Nonetheless, as the recipient of code, docs (even if flawed), personalized help, starting a post with a complaint just depresses those you’re seeking help from.

Where Next?

Popular in Questions Top

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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; somethi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New

We're in Beta

About us Mission Statement