I’m looking for guidance on whether it’s possible to write a Datalog query that will return the following:
Any task (that has a TODO)
the task has either a scheduled or deadline attribute
the minimum of either scheduled or deadline is >7d in the future (+7d)
I typically just use the scheduled attribute, but sometimes I’ve used both.
The problem I’ve run into is the “min of either, if they exist” part.
{
:title [:h2 "🔮 Future Tasks"]
:inputs [:+7d]
:query [
:find (pull ?block [*])
:in $ ?lowdate
:where
; Check whether the task is a TODO
; any valid "task-y" state is allowed
[?block :block/marker ?marker]
(not
[(contains? #{"DONE", "CANCELLED", "CANCELED", "LATER"} ?marker)]
)
; TODO how do I get the minimum of these for the comparison below?!
(or
[?block :block/scheduled ?date]
[?block :block/deadline ?date]
)
; the due date is in range
[(<= ?lowdate ?date)]
] ;query
}
Is this even possible to pull off in a single query (i.e. to pick the “minimum” of the unification between the dates in the or block?
Do you mean this as if either one is in the future show the task?
Or both must be in the future?
I don’t understand the minimum part.
So if I have a task today with scheduled = 15th of December and deadline = 17th of December, should it show?
If I have a task today with schedule = 17th of December and deadline = 24th of December, should it show?
The latter your query already does. The only error in your query is that the :in is incorrect.
There are no rules and thus :in shouldn’t have %. Otherwise the query works.
Thanks! I guess I have to just enumerate all of the possible cases like this due to how Datalog works.
@Siferiax apologies for the confusion, the query I showed was a snippet from a longer query that did include a rule. I fixed it above in case someone else stumbles upon this thread who may not be aware that without rules, including % is incorrect.