ReviewOS

stacks/bun-query-builder

insertInto().values([]) returns empty SQL instead of rejecting the call

#1097
Closed glennmichael123 opened this 22 days ago · 0 comments
22 days ago

Found on main @ 68fd61c, verified by execution. Low severity — filing so it is not rediscovered.

String(db.insertInto('t').values([]).toSQL())
// ""

toSQL() returns the empty string, which then reaches the driver and fails with an opaque error naming neither the table nor the call that produced it.

Suggested

Throw at the call:

[query-builder] values([]): nothing to insert.

Worth deciding, not assuming

"Insert a possibly-empty batch" is a reasonable thing to want — it is the natural shape of insertInto(t).values(rows.filter(...)). But the useful behaviour there is a resolved no-op result ({ affectedRows: 0 }), not an empty SQL string, and that is a small feature rather than this fix. Throwing is the right default until someone asks for it; silently emitting nothing is not a design either way.

Sign in to comment on this issue.