setCase sets the column value using the "CASE WHEN" statement. The x defines the condition/predicate, t is the true (if) case, and 'f' defines the false (else).
(u *sql.UpdateBuilder, column string, w when)
| 201 | // The x defines the condition/predicate, t is the true (if) case, |
| 202 | // and 'f' defines the false (else). |
| 203 | func setCase(u *sql.UpdateBuilder, column string, w when) { |
| 204 | u.Set(column, sql.ExprFunc(func(b *sql.Builder) { |
| 205 | b.WriteString("CASE WHEN ").Wrap(func(b *sql.Builder) { |
| 206 | w.Cond(b) |
| 207 | }) |
| 208 | b.WriteString(" THEN ") |
| 209 | w.Then(b) |
| 210 | b.WriteString(" ELSE ") |
| 211 | w.Else(b) |
| 212 | b.WriteString(" END") |
| 213 | })) |
| 214 | } |
| 215 | |
| 216 | func isPrimitive(v any) bool { |
| 217 | switch reflect.TypeOf(v).Kind() { |