Ecto 查询 where testA and (testB or testC)
Ecto query where testA and (testB or testC)
我有一个看起来像这样的架构;
schema "things" do
field(:title, :string)
field(:temperature, :integer)
field(:weight, :integer)
end
我想编写一个等同于以下 SQL 的 Ecto 查询,但我似乎无法将其转换为有效形式。
select * from things where temperature <= 200 and (weight is null or weight > 2);
如何在 Ecto 中执行此操作?
语法和SQL几乎一样:
from(t in Thing, where: t.temperature <= 200 and (is_nil(t.weight) or t.weight > 2))
我有一个看起来像这样的架构;
schema "things" do
field(:title, :string)
field(:temperature, :integer)
field(:weight, :integer)
end
我想编写一个等同于以下 SQL 的 Ecto 查询,但我似乎无法将其转换为有效形式。
select * from things where temperature <= 200 and (weight is null or weight > 2);
如何在 Ecto 中执行此操作?
语法和SQL几乎一样:
from(t in Thing, where: t.temperature <= 200 and (is_nil(t.weight) or t.weight > 2))