Query journal entries between dates and return also the references to those journals

i read through many posts all over the internet, but I can’t figure this out:
I have my journal pages where I write most of my stuff, but there are occasions when I write something on a different page and reference a specific journal date.

what I want is a query that returns journal pages between two dates, but also returns all the references to those dates.

Could you provide any examples of what (blocks, queries, most similar web findings that) you have so far?

edit:
here is what I mean explained with a graphic

pages:

what I want from the query:

Sorry, but I need the markdown of the blocks:

  • How do you write down an event?
    • As plain text, i.e. event nr 1
    • As a task, i.e. TODO event nr 1 etc.
  • How do you reference an event on its reflection?
    • As a block, i.e. with ((block-id))
    • As a journal page, i.e. with [[date]]

this is what I have so far, but this only returns the journal pages themself:

#+BEGIN_QUERY
{
   :query [
           :find (pull ?b [*])
           :in $ ?start ?end
           :where
           (between ?b ?start ?end)
           ]
    :inputs [ start-date end-date ]
  }
#+END_QUERY

is this example enough?

//page "2024-02-13"
- event nr 1:
	- what is happening
	- what is planned
	

//page "2024-02-24"
- reflection of [event nr 1]([[2024-02-13]]):
	- what was good
	- what was bad

Your approach is far from typical. Let’s begin with something like this:

#+BEGIN_QUERY
{
 :query [
   :find (pull ?b [*])
   :in $ ?start ?end
   :where
     (or-join [?b ?start ?end]
       (between ?b ?start ?end)
       (and
         [?b :block/page ?r]
         [?c :block/page ?r]
         [?c :block/refs ?j]
         [?j :block/journal-day ?d]
         [(>= ?d ?start)]
         [(<= ?d ?end)]
       )
     )
 ]
 :inputs [ start-date end-date ]
}
#+END_QUERY

wow, this is crazy! thank you for that!
I really struggle to understand datalog… I started using logseq 2 months ago, but this is my first attempt to use the queries
is it possible to return the entire page if it is a journal page, or just the block where the date is referenced? and how would I sort the results by the date referenced/of the journal page?

what would be a more typical approach? I am willing to explore better methods.
what I really like about how I am doing this, is that I can achieve a similar goal like here, but without the overhead of creating hierarchies or assigning block properties. also I can query for years, decades, centuries etc. by just adjusting the query input

Everybody struggles with Datalog. Your first attempts with queries should be for simpler things.

It is mostly possible, but shouldn’t bother before deciding the overall approach or workflow.

  • If the alternative is to maintain queries with complicated Clojure code, the overhead is comparable.
  • If by “hierarchies” you mean namespaces:
    • they are not generally needed
    • but should not be immediately excluded in their simplest (shallow) forms
      • these have minimal overhead
  • Properties are here to stay, especially in the coming database version.
    • If you want to use meta-data, properties’ overhead:
      • is totally justified/worthy
      • can be minimized through templates
  • Generally, individual tools cannot be judged as good, bad, heavy, difficult etc.
    • They should be considered only within overall workflows that fit them.

The primary issue is that you identify the events by their date. In contrast, the typical approach is to either:

  • use a block reference, i.e. ((block-id))
    • best for short events, like meetings
  • use a unique name for each event, then refer to them by page-references
    • even if you let those pages empty
    • examples:
      • [[event nr 1]]
        • It is important instead of - event nr 1: to use - [[event nr 1]]:
      • [[EURO 2024]]
        • An event that lasts more than one day.
      • [[2024/EURO]]
        • Namespaced version with easy auto-complete.

ok thanks a lot for the insight! deciding the best approach for current and future needs is such a daunting task.

1 Like