Tutorial: Building with CleaveDB
Removing Relationships (SEVER & UNLINK)
When an association between two entities ends—such as unfriending a user, revoking a member's role, or removing an external URL reference—CleaveDB provides dedicated commands for each relationship engine: SEVER for graph bonds in _bonds, and UNLINK for document and URL links in _links.
1. SEVER — Removing Graph Bonds
Use SEVER to remove graph edges between documents. You can target a single named label or destroy all bonds between the pair:
-- Remove a specific labeled edge
SEVER "users:jane" FROM "users:juan" AS "friend"
-- Remove ALL bonds between Jane and Juan regardless of label
SEVER "users:jane" FROM "users:juan"When a specific label is severed, any other bonds between the two documents (such as "co_worker") remain completely intact.
2. UNLINK — Removing Document & URL Links
Use UNLINK to detach structural document pointers or external web URLs from _links:
-- Remove a document link
UNLINK "users:jane" FROM "users:juan"
-- Remove a specific labelled link
UNLINK "users:jane" FROM "users:juan" AS "mentor"
-- Remove an external web URL reference
UNLINK "users:jane" FROM "https://github.com/jane"UNLINK specifically targets records in the _links catalog without disturbing semantic graph edges in _bonds.
3. Integrity Healing (HEAL)
If documents are permanently deleted with INCINERATE or external references break, use HEAL to automatically clean up orphaned edges:
| Scope | Command | Effect |
|---|---|---|
| Bonds only | HEAL BONDS | Removes edges whose source or target document no longer exists in _bonds |
| Links only | HEAL LINKS | Removes links whose source or target document no longer exists in _links |
| Full repair | HEAL ALL | Audits and heals both bonds and links, plus secondary index integrity |
