Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: $with is undefined on withReplicas #1834

Closed
malonehedges opened this issue Jan 26, 2024 · 9 comments · Fixed by #1839
Closed

[BUG]: $with is undefined on withReplicas #1834

malonehedges opened this issue Jan 26, 2024 · 9 comments · Fixed by #1839
Labels
bug Something isn't working priority Will be worked on next qb/crud

Comments

@malonehedges
Copy link
Contributor

What version of drizzle-orm are you using?

0.29.3

What version of drizzle-kit are you using?

0.20.10

Describe the Bug

const db = withReplicas(primaryDb, [readDb])
const subquery = db.$with('changes').as(db.select().from(users))
// ^ $with is undefined

Expected behavior

$with should work, or the type should be different.

I'm happy to specify if i'm using the primary or a read replica, or construct the query another way if possible.
As-is, the types suggest this works when it doesn't.

Environment & setup

I am using node-postgres as my database.

@malonehedges malonehedges added the bug Something isn't working label Jan 26, 2024
@malonehedges
Copy link
Contributor Author

resolved by #1839

@AndriiSherman
Copy link
Member

@malonehedges thanks a lot! Will merge your PR

@hirbod
Copy link

hirbod commented Mar 19, 2024

@AndriiSherman can you merge this? We patch-packages, but would be nice to resolve this upstream

@nateeo
Copy link

nateeo commented Apr 19, 2024

@malonehedges thanks for raising this, I encountered this issue and you saved me a whole bunch of debugging time <3

@Yuval-Peled
Copy link

Yuval-Peled commented Jul 18, 2024

Since the solution isn't merged yet, this is the hacky solution we're using:

export db = withReplicas(...);
// @ts-ignore
db.$with = db.$primary.$with;

@janvorwerk
Copy link

Since the solution isn't merged yet, this is the hacky solution we're using:

export db = withReplicas(...);
// @ts-ignore
db.$with = db.$primary.$with;

@Yuval-Peled, out of curiosity, how do you deal with the fact that $primary is only defined when you enable read replicas? Does it mean you always use read replicas? Even in dev?

@Yuval-Peled
Copy link

Yuval-Peled commented Aug 26, 2024 via email

@L-Mario564 L-Mario564 added priority Will be worked on next qb/crud labels Oct 17, 2024
@dalechyn
Copy link
Contributor

dalechyn commented Dec 1, 2024

This patch fixed our use of replicas – without it, you cannot use replicas with drizzle.
This needs to be merged.

@AndriiSherman
Copy link
Member

Fixed in drizzle-orm@0.37.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority Will be worked on next qb/crud
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants