squirrel icon indicating copy to clipboard operation
squirrel copied to clipboard

fix: support non-string values in Case When/Then/Else clauses

Open Yanhu007 opened this issue 7 months ago • 0 comments

Fixes #388

Problem

Passing non-string, non-Sqlizer values (like integers) to Case().When() or .Else() fails with:

expected string or Sqlizer, not int

This makes it impossible to use CASE WHEN with numeric values:

sq.Case("order_no").
    When("'ORD001'", 500).  // ← fails: 500 is int
    Else(0)                       // ← fails: 0 is int

Fix

In part.ToSql(), treat non-string, non-Sqlizer values as parameterized arguments (using ? placeholder) instead of returning an error. This is consistent with how other parts of squirrel handle arbitrary values.

Before: "expected string or Sqlizer, not int" error After: CASE order_no WHEN 'ORD001' THEN ? ELSE ? END with args [500, 0]

All existing tests pass.

Yanhu007 avatar Apr 14 '26 20:04 Yanhu007