Circumflex标志/ Pin / Cap运算符(^)在Elixir中做了什么?

时间:2015-09-04 19:09:47

标签: elixir

我正在浏览Ecto文档,当我到达插值部分时,Ecto使用Circumflex(^)符号,就像这样。

def with_minimum(age, height_ft) do
    from u in User,
  where: u.age > ^age and u.height > ^(height_ft * 3.28)
end

让我想知道,它做了什么? : - )

1 个答案:

答案 0 :(得分:3)

在Elixir中,引脚运算符用于模式匹配以匹配变量的当前值。您可以在此处详细了解:http://elixir-lang.org/getting-started/pattern-matching.html

Ecto将pin运算符更改为表示将Elixir值传递给查询的查询插值。你可以说他们的行为有点类似,因为数据库有效地运行查询试图找到匹配的值,但最简单的方法是将其视为查询插值。更多信息:http://hexdocs.pm/ecto/Ecto.Query.html