Add a WHEN <condition> THEN <thenValue> branch. Repeatable — call
multiple times to add multiple branches, evaluated in order.
Two call forms are supported:
.when(conditionObject, thenValue) — condition object using the
same shape as where: clauses ({ age: { [Op.gte]: 18 } }, nested
Op.and/Op.or, etc.).when(column, operator, value, thenValue) — ergonomic shorthand
for a single comparison (mirrors Op.where(col, op, value)).Add a WHEN <condition> THEN <thenValue> branch. Repeatable — call
multiple times to add multiple branches, evaluated in order.
Two call forms are supported:
.when(conditionObject, thenValue) — condition object using the
same shape as where: clauses ({ age: { [Op.gte]: 18 } }, nested
Op.and/Op.or, etc.).when(column, operator, value, thenValue) — ergonomic shorthand
for a single comparison (mirrors Op.where(col, op, value)).Set the ELSE <value> branch. Optional — omitting it yields an implicit SQL NULL.
Render the CASE WHEN ... END SQL fragment (no alias).
Terminal call: returns an [expr, alias] tuple compatible with the
existing attributes: [...] pattern (see attributeToSql() in
sql-compiler.ts, which already knows how to render
[LiteralExpression, alias] tuples without any core changes).
Use the builder directly wherever a raw SQL literal expression is expected.
Fluent builder for a "searched" CASE expression: CASE WHEN cond1 THEN result1 WHEN cond2 THEN result2 ... ELSE else END
Build with
caseWhen(). Terminate with.as(alias)(for use directly in anattributes: [...]array) or.toSQL()/.toLiteral().