FelipeJz
FelipeJz16mo ago

Is there any way to do something similar to a sql left join using queries?

Without needing to send another query for that
6 Replies
Bogdan
Bogdan16mo ago
I was wondering the same thing, the docs say that complex queries, including a join, should be handled with javascript. https://docs.convex.dev/database/reading-data#more-complex-queries
Bogdan
Bogdan16mo ago
also im not seeing a join method on the query
No description
sshader
sshader16mo ago
Yep there's no way to do a join within a single db.query (https://stack.convex.dev/functional-relationships-helpers has some helpers for doing different sorts of joins in JS). Generally making multiple db.query or db.get calls within a single function is fine performance-wise, since the thing running the JS is very close to the database executing the db.query calls.
Functional Relationships: Helpers
In this post, we’ll look at some helper functions to help write code to traverse relationships in a readable, predictable, and debuggable way.
FelipeJz
FelipeJzOP16mo ago
Thank you guys, i ask because i was wondering if i could optimize thinking about the cost of multiple queries in an action
lee
lee16mo ago
Cost in terms of time or database bandwidth? For database bandwidth a join is the same cost whether you do it in javascript or if we exposed a query join syntax. For time you can improve it a little by doing the queries in parallel (with a Promise.all) but that's usually not necessary. Let us know if you're running into any cost issues
ian
ian16mo ago
Also worth mentioning that from an action you can call a single query function which calls ctx.db.query many times. The "query" terminology can be ambiguous, apologies for that.

Did you find this page helpful?