Fork me on GitHub

related to my previous question, now that I’ve transacted this deeply nested data, I need to pull it all out


I need a query that will return an arbitrarily (but finite, no cycles) deep tree of comments


I think pull might be what I want, but I’m struggling to find resources on how to write this query


As long as the comments are set up as refs you can query and shape the output using pull

(as-> '[:find (pull ?branch [*
        :in $ ?organization-uuid
        :where [?branch ::branches/organization ?organization]
               [?organization ::organizations/uuid ?organization-uuid]] $
  (db/q $ org-uuid)
  ;; ...


Reading your previous comment, I’m not sure how datascript stored the value of comments (and I could be missing something), but it may have just taken that vec of comments and set it as the value of :comments (since datascript can store any type for transacted values) - In that case I'm not sure you would be able to leverage any of the query rule system for that subcollection. @lilactown


yeah I’m not sure either tbh. will check


if they did get transacted as entities, will your pull query get all nested comments as well? e.g.

{:id 1
 :comments [{:id 2
             :comments [,,,]}
            {:id 3
             :comments [,,,]}]}


I believe you would have to do something like this (in datomic) by tagging the entity as a component :db/isComponent true but I'm not sure if you can do this with datascript.


@oconn :db/isComponent true is exactly what I wanted!! thank you!