I was browsing through the Ecto documentation, when i got to the interpolation part, where Ecto uses the Circumflex(^) sign, like so.
def with_minimum(age, height_ft) do
from u in User,
where: u.age > ^age and u.height > ^(height_ft * 3.28)
end
Made me wonder, what does it do? :-)
In Elixir, the pin operator is used in pattern matching to match on the current value of a variable. You can read more about it here: http://elixir-lang.org/getting-started/pattern-matching.html
Ecto changes the pin operator to mean query interpolation where you pass an Elixir value to the query. You could argue their behaviour are somewhat similar, because the database is effectively running the query trying to find a value that matches, but the easiest way is to think of it is indeed as query interpolation. More info here: http://hexdocs.pm/ecto/Ecto.Query.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With