Result transform conditional

Yes, using an or-join. We don’t care about the child block, just whether it exists or not.

#+BEGIN_QUERY
{:title "Block has child"
 :query [:find ?has-child (pull ?b [*])
  :where
   [?b :block/marker "TODO"]
   (or-join [?b ?has-child]
     (and
       [?child :block/uuid ?id]
       [?child :block/parent ?b]
       [(not false) ?has-child]
     )
     (and
       (not
         [?child :block/uuid ?id]
         [?child :block/parent ?b]
       )
       [(not true) ?has-child]
     )
   )
 ]
 :result-transform (fn [r]
   (for [[collapsed, b] (partition 2 r)]
     (assoc b :block/collapsed? collapsed)
   )
 )
}
#+END_QUERY

2 Likes