Method: Sequel::SQL::BooleanExpression.from_value_pairs
- Defined in:
- lib/sequel/sql.rb
.from_value_pairs(pairs, op = :AND, negate = false) ⇒ Object
Take pairs of values (e.g. a hash or array of two element arrays) and converts it to a BooleanExpression
. The operator and args used depends on the case of the right (2nd) argument:
- 0..10
-
left >= 0 AND left <= 10
- 1,2
-
left IN (1,2)
- nil
-
left IS NULL
- true
-
left IS TRUE
- false
-
left IS FALSE
- /as/
-
left ~ ‘as’
- :blah
-
left = blah
- ‘blah’
-
left = ‘blah’
If multiple arguments are given, they are joined with the op given (AND by default, OR possible). If negate is set to true, all subexpressions are inverted before used. Therefore, the following expressions are equivalent:
~from_value_pairs(hash)
from_value_pairs(hash, :OR, true)
1084 1085 1086 1087 1088 |
# File 'lib/sequel/sql.rb', line 1084 def self.from_value_pairs(pairs, op=:AND, negate=false) pairs = pairs.map{|l,r| from_value_pair(l, r)} pairs.map!{|ce| invert(ce)} if negate pairs.length == 1 ? pairs[0] : new(op, *pairs) end |