Skip to content

[Pg]: Forward all $with arguments through withReplicas - #6161

Open
godoom wants to merge 1 commit into
drizzle-team:mainfrom
godoom:fix/pg-withreplicas-dollar-with
Open

[Pg]: Forward all $with arguments through withReplicas#6161
godoom wants to merge 1 commit into
drizzle-team:mainfrom
godoom:fix/pg-withreplicas-dollar-with

Conversation

@godoom

@godoom godoom commented Aug 21, 2026

Copy link
Copy Markdown

Summary

  • withReplicas forwarded only the first argument of $with, so db.$with(alias, selection) dropped the CTE selection map on replica queries.
  • $with now spreads all arguments, matching with, select, and the other replica wrappers.
  • Added replica mock tests that assert both alias and selection are forwarded to the chosen replica or $primary.

Test plan

  • Replica tests cover $with on primary, a random replica, a single replica, mixed replica + primary, and a fixed first replica
  • Run cd integration-tests && pnpm exec vitest run tests/replicas/postgres.test.ts
  • Confirm db.$with('sq', { ... }).as(sql\...`)works throughwithReplicas`

Postgres $with accepts an optional selection argument. withReplicas only
forwarded the first argument, so CTE selection maps were dropped when
queries went through a replica.
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