sKeИ ちりこ
sKeИ ちりこ3mo ago

queries when transitioning from prisma

I'm quite new to convex and I'm recently migrating one of my projects from prisma/postgres db to convex. I would like to know the alternatives and the approaches to the following in terms of convex: - relationships - cascading. (deletion) - counts - take, include, exclude (probably filter solves this) - queries with union. e.g. all all the posts of a user including comments. etc etc
4 Replies
Convex Bot
Convex Bot3mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
sKeИ ちりこ
sKeИ ちりこOP3mo ago
So these are my findings: - For relationships, referencing the related table's ID is usually sufficient. - For cascading deletions, either use triggers or manually fetch and delete in a loop. For example, fetch a post by its ID, then retrieve all its comments and delete them individually. - For counting, you can either fetch and collect the relevant data or use an aggregate helper. - For unique data entry, query the table to check if data already exists. - Filtering is already supported, but be sure to use indexes wherever possible for better performance. - For include-like behavior, fetch related data separately and combine them manually. For example, get the post, then fetch the author and all the comments, and merge them into a single response. - For exclude, simply use filters. I’m aware of Convex Ent, but since it’s in maintenance mode, I’m not sure about using it. If there are better or more efficient ways to do this, I’d love to know. I’m planning to use Convex in future projects, so I’m just trying to learn as much as I can.
erquhart
erquhart3mo ago
This is the canonical reference, it's not new but still valid: https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
sKeИ ちりこ
sKeИ ちりこOP3mo ago
Thank you I will check it out

Did you find this page helpful?