Skip to content

Instantly share code, notes, and snippets.

@dbieber
Last active July 23, 2022 03:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbieber/f54996410a10d755b5ea61dd9923164b to your computer and use it in GitHub Desktop.
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
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