fix(sqlite): alias remapped select columns for D1 batch object rows - #6040
Open
arimu1 wants to merge 1 commit into
Open
fix(sqlite): alias remapped select columns for D1 batch object rows#6040arimu1 wants to merge 1 commit into
arimu1 wants to merge 1 commit into
Conversation
D1 batch collapses ROWS_AND_COLUMNS into objects, so duplicate SQL column names (e.g. users.id + posts.id) lose values before mapResultRow. Emit distinct AS aliases from the selection path so object keys stay unique. Fixes drizzle-team#6038
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.
Summary
Fixes #6038
db.batch()on Cloudflare D1 returns object rows (client convertsROWS_AND_COLUMNS→ objects). When a join select remaps two columns that share the same SQL name (e.g.users.id+posts.idasuserId/postId), those keys collapse andd1ToRawMappingshifts values — while the identical query via.all()/.raw()stays correct.Sqlite
buildSelectionnow emits distinctASaliases from the selection path (ortable_columnfor multi-table selects that keep the raw column name), so object-row drivers keep one key per selected field.mapResultRowstill maps by ordinal position.Test plan
vitest run tests/sqlite-selection-aliases.test.ts— asserts generated SQL includes"users"."id" as "userId","posts"."id" as "postId","posts"."title" as "postTitle"AI disclosure
Prepared with Claude Code / Cursor assistance. I reviewed the D1 batch → object-row path and the sqlite selection builder, and verified the new unit test locally.
Made with Cursor