Method: Sequel::SQL::Builders#case

Defined in:
lib/sequel/sql.rb

#case(*args) ⇒ Object

Return an SQL::CaseExpression created with the given arguments. The first argument are the WHEN/THEN conditions, specified as an array or a hash. The second argument is the ELSE default value. The third optional argument is the CASE expression.

Sequel.case({a: 1}, 0) # SQL: CASE WHEN a THEN 1 ELSE 0 END
Sequel.case({a: 1}, 0, :b) # SQL: CASE b WHEN a THEN 1 ELSE 0 END
Sequel.case({{a: [2,3]} => 1}, 0) # SQL: CASE WHEN a IN (2, 3) THEN 1 ELSE 0 END
Sequel.case([[{a: [2,3]}, 1]], 0) # SQL: CASE WHEN a IN (2, 3) THEN 1 ELSE 0 END


370
371
372
# File 'lib/sequel/sql.rb', line 370

def case(*args)
  SQL::CaseExpression.new(*args)
end