Make Advanced Queries reusable

Three simple ideas to increase reusability of Advanced Queries

  1. Make :rules customizable in config.edn
    Just like it works now for :query/result-transforms & :query/views. It is pretty easy to implement.
  2. Add :embed-block as :inputs
    Just like :current-block works now. But :embed-block should be the :db/id of block which embeds the block with query. With that approach we can use the same one query with block embedding and parametrize it via embed block properties. Example:
    - param:: value
      {{embed ((666cd068-133c-4b30-9df4-1dd8a94179cb))}}
    - param:: another-value
      {{embed ((666cd068-133c-4b30-9df4-1dd8a94179cb))}}
    
    Where the ((666cd068-133c-4b30-9df4-1dd8a94179cb)) is the reference to block with query:
    #+BEGIN_QUERY
    {
      :inputs [:embed-block]
      :query [:find ?value
      :in $ ?embed-block
      :where
        (property ?embed-block :param ?value)
    
        ;; ... any way of usage ?value
      ]
    }
    #+END_QUERY
    
    This will lead to result: the only one query, but ability to parametrize it as we need:
  3. Add :query-result as :inputs
    Now the result of query in parent block can be used in child blocks via {{function ...}} macro, but this way is very limited. It would be very useful to reuse the query result in child blocks via advanced queries.

:pray: Vote for this comment and the whole topic

6 Likes