After playing with this, I came to the conclusion that, although the sequel pearl tends to be “simple, flexible, and powerful,” its syntax becomes quite confusing when things get a little complicated.
Here is my best attempt at your request:
DB[:testtable].select(
Sequel.case([
[{code: 'a'}, 'x'],
[{code: ['m', 'n']}, 'y'],
[{class: ['p', 'q'], (Sequel.expr(:amount) > 0) => true}, 'z']],
nil).
as(:status)
)
The result is the following (almost correct) SQL:
SELECT (
CASE WHEN (`code` = 'a') THEN 'x'
WHEN (`code` IN ('m', 'n')) THEN 'y'
WHEN ((`class` IN ('p', 'q')) AND ((`amount` > 0) IS TRUE)) THEN 'z'
ELSE NULL END) AS `status` FROM `testtable`
, case. , .
, SQL, .