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)
その正確な形式に従う必要はありませんが、プログラムで条件を構築できるようにしたいので、このクエリを手動で構築できるだけでは不十分です。