Advanced queries and the database documentation?

Hi

I have already found the following information:

This is useful information but I am still not able to write the queries I need.

What I am still missing is:

  • Information about which attributes belong to the same element (i.e. share the same element ID).
  • The information which values of which attributes in turn contain a reference to an element ID of another element.
  • And I still don’t understand certain parts of the syntax.

My question on the first two points is:
Is there any documentation about those aspects?

On the last point, let me give you a concrete example:

The following query basically works fine:

   {:title "⭕ open TODOs in the journal ..."
        :query [:find (pull ?h [*])
                           :where
                           [?h :block/marker ?marker]
                           [(contains? #{"TODO" "WAITING"} ?marker)]
                           [?h :block/page ?p]
                           [?p :block/journal? true]]
        :result-transform (fn [result] (sort-by (fn [h]
                                       (get h :block/priority "Z")) result)))
        :collapsed? false}

I thought I understood how this query works and tried to enhance it.
I want to exclude all the TODO and WAITING blocks that contain the keyword “subtask”.

So if I have the structure …

  • TODO main task one
  • TODO main task two
    • TODO subtask 2.1
    • TODO subtask 2.2

… I want the query to return only the two “main tasks” and NOT the subtasks (2.1 and 2.2.).

So I added this part to the query:

               [?h :block/content ?content]
               (not [(contains? #{"subtask"} ?content)])

which leads to this query…

	{:title "⭕ open TODOs in the journal ..."
    :query [:find (pull ?h [*])
                       :where
                       [?h :block/marker ?marker]
                       [(contains? #{"TODO" "WAITING"} ?marker)]
                       [?h :block/content ?content]
                       (not [(contains? #{"subtask"} ?content)])
                       [?h :block/page ?p]
                       [?p :block/journal? true]]
    :result-transform (fn [result] (sort-by (fn [h]
                                   (get h :block/priority "Z")) result)))
    :collapsed? false}

But this query is not working. I assume there are some very basic things I still don’t understand.

SUMMARY:

  • Is there any documentation about which attributes belong together to which elements?
  • Is there documentation on which attributes contain element IDs as values?
  • Can someone help me with the query above?

Thanks
Chris

1 Like