IDIR
IDIR16mo ago

delete many ? cascade delete ?

Does convex have support for filter delete as in regular sql ? or a cascade delete for forein keys ? Do I have to query all of them first then delete one by one ? if that's the case is there a batch delete functionality ? I initially had those relations in a single array field but decided to spread them into their own tables since I couldn't find anything on efficiently updating array fields . (my guess i that i would have to query it ,update it using custom action then replace the whole field ?). Google doesn't help either whenever I try to lookup something it's gives some random stuff that has no relation to convex at all .
3 Replies
jamwt
jamwt16mo ago
the short answer is: not out of the box. but I'd check out this article for more about this: https://stack.convex.dev/functional-relationships-helpers
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.
jamwt
jamwt16mo ago
it talks through strategy for automating batch work and relational traversal in particular, asyncMap for all your deletes will just do what you want given an array of document ids we have some plans to provide some higher level ORM-style abstractions to automate some of these things for those who want to use them. but we're thinking those through carefully to make sure we get them right, and they'd be built on these same convex primitives and open source so you could always reach into and modify them for now, this will do the trick:
const ids = ...;
await asyncMap(ctx.db.delete, ids);
const ids = ...;
await asyncMap(ctx.db.delete, ids);
jamwt
jamwt16mo ago
convex helpers repo is here, which has lots of good stuff in it: https://github.com/get-convex/convex-helpers/tree/main
GitHub
GitHub - get-convex/convex-helpers: A collection of useful code to ...
A collection of useful code to complement the official packages. - GitHub - get-convex/convex-helpers: A collection of useful code to complement the official packages.

Did you find this page helpful?