Task: LATER OR TODO
;; Scenario 1: Task has a scheduled date today or in the future but less than ‘next’
;; Scenario 2: Task has a deadline today or in the future but less than ‘next’
;; Scenario 3: Task has both scheduled and deadline, where the scheduled date has passed but the deadline is still in the future
My attempt
{:title "📅 MINE NEXT"
:query [:find (pull ?b [*])
:in $ ?start ?next
:where
[?b :block/marker ?marker]
[(contains? #{"LATER" "TODO"} ?marker)]
(or
;; Scenario 1: Task has a scheduled date today or in the future but less than 'next'
(and
[?b :block/scheduled ?scheduled]
[(>= ?scheduled ?start)] ; Scheduled today or in future
[(< ?scheduled ?next)]) ; But less than 'next'
;; Scenario 2: Task has a deadline today or in the future but less than 'next'
(and
[?b :block/deadline ?deadline]
[(>= ?deadline ?start)] ; Deadline today or in future
[(< ?deadline ?next)]) ; But less than 'next'
;; Scenario 3: Task has both scheduled and deadline, where the scheduled date has passed but the deadline is still in the future
(and
[?b :block/scheduled ?scheduled]
[?b :block/deadline ?deadline]
[(< ?scheduled ?start)] ; Scheduled has passed
[(>= ?deadline ?start)]) ; But deadline is still in future
)]
:inputs [:today :7d-after]
:collapsed? false}
I was trying to create a similar Overdue
Query –>
;; Scenario 1: Task whose Scheduled date has passed
;; Scenario 2: Task whose Deadline date has passed
;; Scenario 3: Exclude tasks where scheduled date has passed but the deadline is still in the future
I just tried according to what you said, Updated the code in the question. The query produces no output. I have already created tasks in my logesq covering those scenarios.
Also, my knowledge is very limited. I went through bunch of docs mentioned on logseq docs, discord and youtube. But i have bearly gained the knowlege to read the query even then i am still not sure on some parts.
The documentation on logseq docs is very confusing. The first guide https://www.learndatalogtoday.org/ mentions no longer works.
Discord pinned message, says bunch of defination Discord –>
Datalog
------ a query language used for databases
Datascript
--- a flavor of Datalog written in Clojure. Logseq currently uses Datascript.
Datomic
----- a different flavor of Datalog written in Clojure. (Some tutorials for Datomic may be helpful, but ymmv)
Hiccup
------- a language used to generate HTML, you can use it in an advanced query's custom view ( :view )
But logseq docs dosen’t say it usses DataScript and all learning resource points to some Datalog tutorial.
If you don’t mind can you help me with above Next
and Overdue
query, just this once. And point me to some learning resource.
Currently all i need is those two query for task management. Been spending last 3 days with query. But i am just going round and round.
- Try replacing
(or
with (or-join [?start ?next ?b]
- Prefer replacing
:7d-after
with :+7d
You can read the archived version, but the code may not work.
Edit: i didn’t understand the syntax of when you said `Try replacing (or
with (or-join [?start ?next ?b]
,so was confused of where to replace and how much. Someone on discord mentioned to try what you mentioned. And it worked.
I went to learndatalogtoday.org github and built a local version, went through all 8 chapters. Now i know more but still not enough to be able to build the my version of Next
and overdue
query.
This is the working version of overdue
{:title [:h3 "🔥 Overdue"]
:query [:find (pull ?b [*])
:in $ ?day
:where
[?b :block/marker ?marker] ; Task must have the "TODO" marker
[(contains? #{"LATER" "TODO"} ?marker)]
(or
[?b :block/scheduled ?d] ; Task has a scheduled date
[?b :block/deadline ?d]) ; Task has a deadline
[(< ?d ?day)] ; Task’s scheduled or deadline date is in the past (overdue)
]
:inputs [:today] ; Use today's date as input for comparison
:table-view? false}
It currently shows -
;; Scenario 1: Task whose Scheduled date has passed from today
;; Scenario 2: Task whose Deadline date has passed from today
How to add this →
;; Scenario 3: Exclude tasks where scheduled date has passed but the deadline is still in the future
Solved it.
{:title [:h1 "📅 NEXT"]
:query [:find (pull ?b [*])
:in $ ?start ?next
:where
[?b :block/marker ?marker]
[(contains? #{"LATER" "TODO"} ?marker)]
(or-join [?start ?next ?b]
;; Scenario 1: Task has a scheduled date today or in the future but less than 'next'
(and
[?b :block/scheduled ?scheduled]
[(>= ?scheduled ?start)] ; Scheduled today or in future
[(< ?scheduled ?next)]) ; But less than 'next'
;; Scenario 2: Task has a deadline today or in the future but less than 'next'
(and
[?b :block/deadline ?deadline]
[(>= ?deadline ?start)] ; Deadline today or in future
[(< ?deadline ?next)]) ; But less than 'next'
;; Scenario 3: Task has both scheduled and deadline, where the scheduled date has passed but the deadline is still in the future
(and
[?b :block/scheduled ?scheduled]
[?b :block/deadline ?deadline]
[(< ?scheduled ?start)] ; Scheduled has passed
[(>= ?deadline ?start)]) ; But deadline is still in future
)]
:inputs [:today :+7d]
:collapsed? false}
{:title [:h3 "🔥 Overdue"]
:query [:find (pull ?b [*])
:in $ ?day
:where
[?b :block/marker ?marker] ; Task must have the "TODO" marker
[(contains? #{"LATER" "TODO"} ?marker)]
(or-join [?b ?day]
;; Scenario 1: Scheduled date has passed, don't include block that have deadline
(and
[?b :block/scheduled ?d] ; Task has a scheduled date
(not [?b :block/deadline _])
[(< ?d ?day)] ; Scheduled date is in the past (overdue)
)
;; Scenario 2: Deadline date has passed
(and
[?b :block/deadline ?d] ; Task has a deadline
[(< ?d ?day)] ; Deadline date is in the past (overdue)
)
;; Scenario 3: Scheduled and deadline date has passed
(and
[?b :block/scheduled ?scheduled] ; Task has a scheduled date
[(< ?scheduled ?day)] ; Scheduled date has passed
[?b :block/deadline ?deadline] ; Task has a deadline
[(< ?deadline ?day)] ; Deadline date has passed
))]
:inputs [:today] ; Use today's date as input for comparison
:table-view? false}