SQL Expressions: CASE
Both types of CASE expressions are supported:
u := tables.USERS().As("u")
// 'simple' CASE
// CASE u.username
// WHEN 'bob' THEN 1
// WHEN 'alice' THEN 2
// ELSE 3
// END
Case(u.USERNAME).
When("bob", 1).
When("alice", 2).
Else(3)
// general CASE
// CASE
// WHEN u.username = 'bob' THEN 'one'
// WHEN u.username = 'alice' THEN 'two'
// ELSE 'three'
// END AS 'case_expr'
CaseWhen(u.USERNAME.EqString("bob"), "one").
When(u.USERNAME.EqString("alice"), "two").
Else("three").
As("case_expr") // <-- aliasing a CASE expression