Fork me on GitHub
#datascript
<
2020-03-21
>
lilactown17:03:14

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

lilactown17:03:55

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

lilactown17:03:24

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

oconn19:03:17

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

(as-> '[:find (pull ?branch [*
                             {::branches/event-automation-records
                              [*
                               {::event-automation-records/event
                                [::events/uuid
                                 ::events/name]}]}])
        :in $ ?organization-uuid
        :where [?branch ::branches/organization ?organization]
               [?organization ::organizations/uuid ?organization-uuid]] $
  (db/q $ org-uuid)
  ;; ...
  )

oconn19:03:02

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) https://github.com/tonsky/datascript#differences-from-datomic - In that case I'm not sure you would be able to leverage any of the query rule system for that subcollection. @lilactown

lilactown21:03:31

yeah I’m not sure either tbh. will check

lilactown21:03:07

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 [,,,]}]}
?

oconn21:03:06

I believe you would have to do something like this (in datomic) https://docs.datomic.com/on-prem/pull.html#org32b7414 by tagging the entity as a component :db/isComponent true but I'm not sure if you can do this with datascript.

lilactown23:03:37

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