fix(bun-sql): disable buggy tagged template query generation in postgres driver#5824
Open
Dharya-dev wants to merge 1 commit into
Open
fix(bun-sql): disable buggy tagged template query generation in postgres driver#5824Dharya-dev wants to merge 1 commit into
Dharya-dev wants to merge 1 commit into
Conversation
…res driver Disables tagged template compilation for BunSQLDatabase by setting tagged = false in the constructor. Having tagged = true routes select queries through _sqlToQuery(), which compiles chunks into segment arrays. However, the mismatched alignment between query chunks (like columns, identifiers) and template parameter holes breaks Bun's strict segment-to-value length expectations, producing invalid sql (empty SELECT lists) when casing APIs like snakeCase.table are used. Disabling tagged matches SQLite/MySQL bun-sql drivers and neon-http, routing queries safely through client.unsafe(query.sql, params) which maps and executes successfully.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey everyone!
I ran into a problem using the new
snakeCase.tablecasing options with thebun-sqldriver on Postgres, where it would throw a syntax error:DrizzleQueryError: Failed query: select from "users"Root cause
The constructor for
BunSQLDatabasewas hardcoded to enabletagged = truefor Postgres:const db = new BunSQLDatabase(dialect, session, relations, false, true)This directs select queries down the
_sqlToQuery()path, converting them into segment arrays. But Bun's tagged template parser strictly expects the segments array length to match the parameter values length + 1. Since Drizzle generates separate segments for intermediate column references, identifiers, and select fields, the arrays get completely misaligned and collapse to empty column strings.Fix
I changed
taggedtofalsein the constructor. This correctly routes Postgres queries downclient.unsafe(query.sql, params)(matching how SQLite/MySQL bun-sql drivers andneon-httpbehave). It compiles the entire query string properly and maps selection fields successfully with zero bugs.Tested locally, and all package type checks pass cleanly. Let me know if you need any adjustments!