Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retractEntity #230

Open
lilactown opened this issue Feb 26, 2022 · 1 comment
Open

retractEntity #230

lilactown opened this issue Feb 26, 2022 · 1 comment

Comments

@lilactown
Copy link

Provide the capability to retract all the attributes of an entity and any references to it.

https://docs.datomic.com/cloud/transactions/transaction-functions.html

@quoll
Copy link
Contributor

quoll commented Feb 26, 2022

Since this is generating the triples to be removed, it belongs in asami.entities.writer

There are 2 conditions here: top-level-entities and sub-entities. The latter may not be necessary, but I'm going to assume that they are useful.

For a top-level entity:

  1. Get the :db/id (I'll call this the node)
  2. Find all statements that match: [node :tg/owns ?s]. This returns the sub-entity node list.
  3. Delete the node, using the sub-entity node list for recursion...
    • Find all statements that match: [?e ?a node]. Add these to the list of statements to remove.
    • Find all statements that match: [node ?a ?v]. Add these to the list of statements to remove. The set of ?v values contains the referenced data.
    • For each item in the referenced data that matches the sub-entity node list, go back to 3 and repeat.

For an entity that isn't top-level:

  1. Get the :db/id
  2. Get the statement that matches: [?p :tg/owns node]. This is the parent.
  3. Find all statements that match [parent :tg/owns ?s]. This returns the sub-entity node list of the parent.
  4. Perform step 3 from the top-level-entity operations above.

This second process should recurse down, matching the things owned by the same parent, but should not affect siblings/cousins/etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants