Cascading Delete

Automatically delete related Convex documents using existing indexes with atomic or batched modes for data consistency.

Installation

npm install @00akshatsinha00/convex-cascading-delete

About Cascading Delete

A Convex component for managing cascading deletes across related documents. Configure relationships via existing indexes, then delete documents safely knowing all related records will be cleaned up automatically with clear consistency guarantee

Benefits

Use cases

how to delete related documents in Convex database

The convex-cascading-delete component automatically handles related document deletion by leveraging your existing indexes to define relationships. Configure the relationships once, then call the deletion function to remove a document and all its related records atomically.

Convex cascade delete with foreign key relationships

This component uses your existing Convex indexes as relationship definitions to perform cascading deletes. You can configure parent-child relationships and choose between atomic or batched deletion modes depending on your data consistency needs.

prevent orphaned records in Convex mutations

The convex-cascading-delete component ensures referential integrity by automatically cleaning up related documents when you delete a parent record. It provides clear consistency guarantees through atomic operations or batched processing.

Frequently asked questions

Does convex-cascading-delete work with existing Convex indexes?

Yes, convex-cascading-delete leverages your existing Convex indexes to define document relationships. You don't need to create new indexes or modify your schema - the component uses the indexes you've already defined to understand how documents are related and cascade deletions accordingly.

What's the difference between atomic and batched deletion modes?

Atomic mode ensures all related documents are deleted in a single transaction, providing strict consistency but with potential performance limitations for large relationship graphs. Batched mode processes deletions in chunks, offering better performance for large datasets while maintaining eventual consistency.

Can I configure which relationships should cascade delete?

Yes, convex-cascading-delete allows you to configure specific relationships for cascading deletion rather than automatically deleting all related records. You define which index-based relationships should trigger cascades, giving you fine-grained control over the deletion behavior.

Does this component handle circular references between documents?

The convex-cascading-delete component includes safeguards to detect and handle circular references in your document relationships. It prevents infinite deletion loops while ensuring all appropriate related documents are still cleaned up properly.

Links