ReviewOS

stacks/bun-query-builder

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

#1027
Closed glennmichael123 opened this 22 days ago · 0 comments
22 days 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.

Sign in to comment on this issue.