ReviewOS

stacks/bun-query-builder

whereBetween/whereNotBetween emit literal '?' placeholders — invalid on Postgres

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

Summary

whereBetween / whereNotBetween build BETWEEN ? AND ? literally instead of using getPlaceholder. On Postgres the driver needs $n placeholders, so these fail; mixing with a prior .where() yields WHERE name = $1 AND age BETWEEN ? AND ? — $1 and ? in one statement, which Postgres rejects.

Evidence (repro)

selectFrom('users').where({name:'a'}).whereBetween('age',10,20).toSQL()
-> ... WHERE name = $1 AND age BETWEEN ? AND ?

Location

src/client.ts:~3826 and ~3979.

Suggested fix

Build placeholders via getPlaceholder(whereParams.length + 1) / +2, like the other where-helpers.

Severity: high. Found via internal code audit.

9 days ago

Fixed in fd52e92. whereBetween/whereNotBetween now build placeholders via getPlaceholder() from the current param offset, so Postgres gets BETWEEN $2 AND $3 (no more mixed $1 ... ? AND ?) while SQLite/MySQL keep ? AND ?. Regression test added; full suite green.

Sign in to comment on this issue.