ReviewOS

stacks/bun-query-builder

upsert() with no mergeColumns builds an empty SET clause (syntax error)

#1035
Closed glennmichael123 opened this 2 months ago ·
2 months ago

Summary

When mergeColumns is omitted/empty, setCols is [], so the update list is empty, producing ... ON CONFLICT (cols) DO UPDATE SET (Postgres/SQLite) or ... ON DUPLICATE KEY UPDATE (MySQL) with a dangling empty SET — a syntax error.

Location

src/client.ts:~6160-6189.

Suggested fix

When mergeColumns is empty, fall back to DO NOTHING (or default to updating all non-conflict columns), and guard against an empty update list.

Severity: medium. Found via internal code audit.

9 days ago

Fixed in a4e1011. upsert() with no mergeColumns now emits ON CONFLICT (cols) DO NOTHING (Postgres/SQLite) / INSERT IGNORE (MySQL) instead of a dangling empty SET.

While verifying I also fixed a real prerequisite: the lazy bunSql proxy wrapped a {} target, so per spec it wasn't callable and bunSql...`` threw "not a function" — silently breaking every helper-based method. The target is now a function (regression test added).

Heads-up: full upsert execution is still blocked by a separate Bun ${sql(table)} ${sql(values)} interaction + a sqlite values-helper gap — filed as #1052. This issue (the empty-SET SQL generation) and the proxy callability are resolved.

Sign in to comment on this issue.