You can abstract away reusable parts of your queries into rules, give them meaningful names and forget about the implementation details, just like you can with functions in your favorite programming language.
So what about adding a additional :query/rules entry to config.edn, similar to existent :query/views and :query/result-transforms for pre-defined :view, :result-transform functions? Then auto-include these to be usable in every advanced query.
Not so well-working alternatives:
templates - still redundant, as they are just like copy/pasted text; can get ugly for bigger queries
macro/command - didn’t work for me, seems to be not suited well for code incl. format/quoting etc.
To cover the case «multiple locations in graph» you can embed the block with query. It will work if there is no modifications on query OR if it relies on dynamic variables :query-page / :current-page
Yeah, but would the embedded block see the page it was embedded in as the current page or would it see the original block it was from as the current page?
It seems like that doesn’t quite fit the bill, like for example, for this:
Thanks for the hint @stdword, this is a good starting point.
But sometimes more flexibility is needed than just dynamic variables :current-page and co. For example to centralize complex query logic in one place or using arbitrary variable values.
My suggestion is to add additional reusable rules to Logseq globally, similar to reusable functions in code.
Well, I totally have a plans to add something about making queries to 🏛 Full House Templatesplugin.
Don’t have a vision of how it would look like, but you can subscribe for updates here.
Sharing a collection of query functions here: Advanced Query Collection
Feel free to share your query/transforms and views. They will be added to list.
Aaah, I found this thread searching to see if this was possible, so definitely adding my support for this feature! I have a common clause defining an “active” task in a lot of my queries, and would be much cleaner and less error-prone to abstract it into a single rule:
+1 My use case is having the same exclusionary rules across about 8 queries, that’s nearly 8 lines per query and I have to remember to update all 8 queries. I’d love a way to associate a one line rule I can add each time to call on those rules globally.