Advance Query - Sort by latest update datetime

Hi experts,

I’d like to list all completed tasks. But I don’t know how to sort them by updated time.
I tried “get h :block/updated-at” but didn’t work.

Additional question would be how am I suppose to know all the attributes of a block?
Like block/page, block/marker etc

{:title “Done”
:query [:find (pull ?b [*])
[?b :block/marker ?marker]
[(= “DONE” ?marker)]]
:result-transform (fn [result]
(sort-by (fn [h]
(get h :block/created-at)) result))
:collapsed? true}

1 Like

Hi I can’t help you with your specific query because I am learning and struggling with the queries myself. But I can point you to this URL that lists some/all (?) of the attributes: logseq/db_schema.cljs at master · logseq/logseq · GitHub

I am preparing a request for help myself because I have not found a full documentation of the data model. One not only needs to know which attributes there are - but one also needs the information which attributes belong to the same element (share the same element id) and which attribute’s value stores an element id to another element. Without this information I find it hard to write those queries.

1 Like

Thank you Chris.

According to the link you provided, there is an attribute called “updated-at”. But I still don’t know why it didn’t work out.

Solved it by myself

Simple query would work
{{query (and (todo done) (between -7d today))}}


Hi, stumbled across this when I was looking into my own ‘tasks completed today’ query. the :block/updated-at property is only populated on the blocks if you enable the option in config.edn, like so:

  :feature/enable-block-timestamps? true

Then you can query like:

{:title "✅  Done Today"
    :query [:find (pull ?h [*])
            :in $ ?today ?tomorrow
            [?h :block/marker "DONE"]
            [?h :block/updated-at ?d]
            [(> ?d ?today)]
            [(< ?d ?tomorrow)]]
    :inputs [:today :+1d]
    :collapsed? false}