Last active
July 23, 2022 03:04
-
-
Save dbieber/f54996410a10d755b5ea61dd9923164b to your computer and use it in GitHub Desktop.
Roam Research datalog query for references not already placed on a specific page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let container = "Tree of knowledge"; | |
let tag = "zettel"; | |
let ancestorrule=`[ | |
[(ancestor ?child ?parent) | |
[?parent :block/children ?child]] | |
[(ancestor ?child ?a) | |
[?parent :block/children ?child] | |
(ancestor ?parent ?a)] | |
]`; | |
let blocks = window.roamAlphaAPI.q(` | |
[:find ?page_title | |
:in $ % ?container_title ?tag_text | |
:where | |
[?container_page :node/title ?container_title] | |
[?page :node/title ?page_title] | |
(ancestor ?tagged_block ?page) | |
[?tagged_block :block/refs ?tag_page] | |
[?tag_page :node/title ?tag_text] | |
(not (ancestor ?container_block ?container_page) | |
[?container_block :block/refs ?page]) | |
]`, ancestorrule, container, tag) | |
console.log(blocks.map((data, index) => {return `[[${data[0]}]]`}).join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment