Advanced queries support relative values. Here the first two inputs are relative:
#+BEGIN_QUERY
{:title "Blocks in 7ds with a page reference of datalog"
:query [:find (pull ?b [*])
:in $ ?start ?today ?tag
:where
[?b :block/page ?p]
[?p :page/journal-day ?d]
[(>= ?d ?start)]
[(<= ?d ?today)]
[?b :block/ref-pages ?rp]
[?rp :block/name ?tag]]
:inputs [:7d-before :today "datalog"]}
#+END_QUERY
It is not possible to pass relative values (like :today
, :7d-before
, etc). into queries inside of plugins. In many cases this is not an issue since the developer can compute these values; however, as plugins are JSON configurable by their users (e.g. settings) and JSON doesn’t allow computation, users are unable to pass relative-value queries to plugins they might like to reconfigure.
const ids = await logseq.DB.datascriptQuery(`[:find ?uuid
:in $ ?start
:where
[?block :block/uuid ?uuid]
(or
[?block :block/scheduled ?d]
[?block :block/deadline ?d])
[(> ?d ?start)]]`, ":today")
It might even make sense to allow relative values to be embedded directly without declaring inputs:
const ids = await logseq.DB.datascriptQuery(`[:find ?uuid
:where
[?block :block/uuid ?uuid]
(or
[?block :block/scheduled ?d]
[?block :block/deadline ?d])
[(> ?d :today)]]`)
As Logseq is already aware of these relative values, why not exposed a tool via the plugin api?
const ids = await logseq.DB.datascriptQuery(`[:find ?uuid
:in $ ?start
:where
[?block :block/uuid ?uuid]
(or
[?block :block/scheduled ?d]
[?block :block/deadline ?d])
[(> ?d ?start)]]`, logseq.resolveInput(":today"))
Without it, the plugin developer is left to reimplement relative values or otherwise not allow users to add the most useful kinds of custom queries to their query configurable plugins.