Skip to content

fix(bun-sql): disable buggy tagged template query generation in postgres driver#5824

Open
Dharya-dev wants to merge 1 commit into
drizzle-team:betafrom
Dharya-dev:fix/bun-sql-tagged-template-mismatch
Open

fix(bun-sql): disable buggy tagged template query generation in postgres driver#5824
Dharya-dev wants to merge 1 commit into
drizzle-team:betafrom
Dharya-dev:fix/bun-sql-tagged-template-mismatch

Conversation

@Dharya-dev
Copy link
Copy Markdown

Hey everyone!

I ran into a problem using the new snakeCase.table casing options with the bun-sql driver on Postgres, where it would throw a syntax error:
DrizzleQueryError: Failed query: select from "users"

Root cause

The constructor for BunSQLDatabase was hardcoded to enable tagged = true for 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 tagged to false in the constructor. This correctly routes Postgres queries down client.unsafe(query.sql, params) (matching how SQLite/MySQL bun-sql drivers and neon-http behave). 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!

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant