我想使用 Ruby 的 Sequel 生成如下 SQL 查询:
SELECT * FROM Objects WHERE (color = "red" AND shape = "triangle") OR
(color = "blue" AND shape = "square") OR
(color = "green" AND shape = "circle")
我想从条件列表中以编程方式构建此查询,以便可以执行以下操作:
conditions = [[[:color, "red"], [:shape, "triangle"]],
[[:color, "blue"], [:shape, "square"]],
[[:color, "green"], [:shape, "circle"]]]
DB[:Users].where(conditions.sql_or)
它不必遵循那种确切的形式,但我希望能够以编程方式构建条件,因此仅仅能够手动构建这个查询是不够的。