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.).
Logseq simple queries are intended for those not comfortable in datascript/datalog/datomic language. I collect examples of powerful simple queries for future usage:
Find all blocks referencing the page: [[Logseq]], #Logseq or tags:: Logseq. {{query [[Logseq]]}}
Find all pages with page tags tags:: book . {{query (page-tags book)}}
Find all pages with both page tags logseq & queries. {{query (and (page-tags logseq) (page-tags queries))}}
Find all pages with page tags logseq or queries {{query (page-tags logseq queries)}}
Find all Todo blocks doing or now {{query (todo doing now)}}
Find Todo blocks done in last 7 days. {{query (and (todo done) (between -7d today))}}
Find all Todo/Doing Now/Later blocks in current page. {{query (and (todo todo doing now later) (page <% current page %>))}}
Find all Todo/Doing Now/Later blocks where tiensonqin was tagged. {{query (and (todo todo doing now later) [[tiensonqin]]) }}
Have you had any success with queries that exclude attributes? I just started using Logseq and learning about DataScript and having the same issue. While structuring my Logseq graph, I’m doing something similar with tagging my work tasks with #work/todo, and now I need to exclude those pages/tags when looking at my personal tasks.
I can use a simple query {{query (and (task TODO DOING) (not [[work/todo]]) ) }}, but I like the advanced query features like adding a title and initially collapsing.
While it doesn’t directly answer your question (and is more of a workaround), if you tag your main tasks with #MainTask, then you could target that page name in your query. I’m using the below query on my work tasks page - if I can’t find a solution for my personal tasks, I might just start tagging those with something like #NicksTasks.
Hello Nick,
I’m sorry. I have collected the necessary queries and have been getting by with them for a while now.
I haven’t delved any deeper into the matter.