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

Watching Drizzle "with"-queries, not supported? #426

Closed
steveninety opened this issue Nov 30, 2024 · 5 comments
Closed

Watching Drizzle "with"-queries, not supported? #426

steveninety opened this issue Nov 30, 2024 · 5 comments

Comments

@steveninety
Copy link

Doing a Drizzle watched query as per the docs, but instead of db.select(), using db.query.findMany({ with: { someRelationName: true }}), will result in all relations being returned (1) as JSON and (2) as an array of arrays of object-values instead of just... an array of objects.

Am I tapping into an unsupported feature, or is this a bug?

@Chriztiaan
Copy link
Contributor

Chriztiaan commented Nov 30, 2024

Hey @steveninety, I believe this is related to a known issue recently found with mapping the query to raw. Those relational queries depend on Drizzle to map the values back. We will be adding dedicated watch functions to both our Drizzle and Kysely packages to resolve this problem.

You can see a discord thread about it here.
A solution is in PR here, and should be available in the week.

@steveninety
Copy link
Author

Thanks Christiaan! Let's close this issue as soon as the update rolls out.

@Chriztiaan
Copy link
Contributor

Chriztiaan commented Dec 2, 2024

Hey @steveninety, @powersync/[email protected] has been released which addresses this problem.
Documentation available for the new watch function on the DrizzleDb here: https://docs.powersync.com/client-sdk-references/javascript-web/javascript-orm/drizzle#watched-queries

Let me know if it resolves the issues for you.

@steveninety
Copy link
Author

Thank you for the quick work! I just had time to test things out and so far so good, lots of boilerplate gone! And being able to call .watch on the drizzle db instead of the powersync db clears up a possible point of confusion too.

I just see one mistake which is that the result parameter in onResult is inferred as an {}[] in .findFirst() and a {}[][] in .findMany(). Whereas findFirst does indeed return an {}[], the findMany also returns an {}[] and not an {}[][]. Beside that, I think it's fair to assume that they should have been an {} and {}[] in findFirst and findMany respectively. But I can work around it for now!

@steveninety
Copy link
Author

Fixed by #430
Thanks!

I just see one mistake which is that the result parameter in onResult is inferred as an {}[] in .findFirst() and a {}[][] in .findMany(). Whereas findFirst does indeed return an {}[], the findMany also returns an {}[] and not an {}[][]. Beside that, I think it's fair to assume that they should have been an {} and {}[] in findFirst and findMany respectively. But I can work around it for now!

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

No branches or pull requests

2 participants