Matt's Roof Garden

Powered by 🌱Roam Garden

Useful Roam Tips

This is an "Orphan" page. Its core content has not been shared: what you see below is a loose collection of pages and page snippets that mention this page, as well as snippets of this page that were quoted elsewhere.

Attribute tables { DO SCIENCE }

{{attr-table:[[Chapter]]}}

{{attr-table:[``[Chapter]]}}

{{attr-table:Chapter}}

Namespaces

To toggle namespaces do Ctrl-c then Ctrl-l

Namespaces are anything in a page title the is before a / They denote different types of pages and can be toggled in 3 levels

to show the whole namespace

to show the first letter of the namespace

to hide the namespace

they can also be controlled by css using

/* Namespace text color [[roam/css]] when using CTRL+C CTRL+L || CMD+C CMD+L */
.rm-page-ref-namespace-color {
    color: blue !important;
    font-weight: 600;
    transition: color .3s ease;
}
.rm-page-ref-namespace-color:hover {
    color: purple !important;
    text-decoration: none;
    transition: color .3s ease;
}
span[data-link-title^="template"] .rm-page-ref:before {
    content: "\01F4DA";
}

My Useful Queries

Show a random block from a page

:q [:find [[rand 1 ?t]]    :where 
    [?e :node/title "quotes"]
    [?e :block/children ?x]
    [?x :block/string ?t] ]
:q [:find ?PageName ?attrValue ?id
    :where 
      [?node :node/title ?PageName]
      [?node :block/children ?block]
      [?block :block/string ?attrValue]
      [?block :block/uid ?id]
      [(re-find #"test" ?PageName)]
      [(re-find #"(?<=::).*" ?attrValue) ?attrValue]
  ]
:q [:find (count ?n)
   :where
   [?n :node/title _]]

:q [:find (count ?t)  :where 
    [?e :node/title "quotes"]
    [?e :block/children ?x]
    [?x :block/uid ?id]
    [?x :block/string ?t] 
    [(< ?id (rand (count ?t)))]]
(== ?id (rand (count ?t)))

children of rand block

:q [:find [rand 1 ?t]    :where 
    [?e :node/title "quotes"]
    [?e :block/children ?x]
    [?x :block/string ?t]
    [?t]
]

Show a random block under a parent block

:q [:find [[rand 1 ?t]]    
    :where 
      [?e :block/uid "BLOCK_REF_ID"]
      [?e :block/children ?x]
      [?x :block/string ?t] ]

:q [:find ?t
    :where 
      [?e :block/uid "F1aQG0uDB"]
      [?e :block/children ?x]
      [?x :block/string ?t ] 
      [(rand 1 ?t)]
]

:q [:find [rand 1 ?t]
:where [?e :block/uid "n2DUzfNn_"][?e :block/children ?x] [?x :block/string ?t] ]

Show all pages that contain a word


:q [:find ?title ?s, ?r
    :where 
        [?e :node/title ?title]
        [?e :block/children ?x]
        [?x :block/string ?s] 
        [(re-matches #"(?i)\b.*(Cover).*" ?s)]
        [?x :block/uid ?r]      
    ]

:q [:find ?title ?s, ?r
    :where 
        [?e :node/title ?title]
        [?e :block/children ?x]
        [?x :block/string ?s] 
        [(re-pattern "(?i)\b.*(Cover).*" ?s)]
        [?x :block/uid ?r]      
    ]

:q [:find ?title ?s, ?r :where [?e :node/title ?title][?e :block/children ?x] [?x :block/string ?s][(re-pattern "Cover*" ?s)] [?x :block/uid ?r]
]

Show blocks from specific page that contain a word


:q [:find [?s ?r]
    :where 
        [?e :node/title "quotes"]
        [?e :block/children ?x]
        [?x :block/string ?s] 
        [(re-matches #"(?i)\b.*(zerp).*" ?s)]
        [?x :block/uid ?r]      
    ]

:q [:find ?s ?r :where [?e :node/title "quotes"][?e :block/children ?x] [?x :block/string ?s][(re-matches #"(?i)\b.*(zerp).*" ?s)] [?x :block/uid ?r]
]

Show child blocks under specific parent that contain a word

:q [:find ?s ?r
    :where 
        [?e :block/uid "xmJZyIEqJ"]
        [?e :block/children ?x]
        [?x :block/string ?s]
        [(re-matches #"(?i).*{{\[\[TODO\]\]}}.*" ?s)]
        [?e :block/uid ?r]      
    ]

:q [:find ?s ?r :where [?e :block/uid "xmJZyIEqJ"][?e :block/children ?x] [?x :block/string ?s][(re-matches #"(?i).*{{\[\[TODO\]\]}}.*" ?s)] [?e :block/uid ?r]
]

Show blocks that contain a word (partially working)

Can also be done with 0dltrvUHn

for some reason this does not like blocks that start and end with quotes ""

:q [:find ?s, ?r
    :where 
        [?e :node/title ?title]
        [?e :block/children ?x]
        [?x :block/string ?s] 
        [(re-matches #"(?i)\b.*(Cover).*" ?s)]
        [?x :block/uid ?r]      
    ]

:q [:find ?s, ?r :where [?e :node/title ?title][?e :block/children ?x] [?x :block/string ?s][(re-matches #"(?i)\b.*(Cover).*" ?s)] [?x :block/uid ?r]
]

Find all attributes on specific page

:q [:find ?s 
    :where 
        [?e :node/title "test"]
        [?e :block/children ?x]
        [?x :block/string ?s] 
        [(re-find #"(?<=\#)(\w+)" ?s)]
             
    ]
:q [:find ?attribute ?attributeValue ?id
    :where 
      [?c :node/title "test"]
      [?c :block/children ?x]
      [?x :block/string ?s] 
      [?x :block/uid ?id]
      [(re-find #".+?(?=::)" ?s) ?attribute]
      [(re-find #"(?<=::)(.*)" ?s) ?attributeValue]
    ]
:q [:find ?PageName ?attrValue ?id
    :where 
      [?node :node/title ?PageName]
      [?node :block/children ?block]
      [?block :block/string ?attrValue]
      [?block :block/uid ?id]
      [(re-find #"test" ?PageName)]
      [(re-find #"(?<=::).*" ?attrValue) ?attrValue]
  ]

:q [:find ?PageName ?attrValue ?id :where [?node :node/title ?PageName][?node :block/children ?block] [?block :block/string ?attrValue][?block :block/uid ?id]

Recursively return all blocks of a page (not working)

Show linked references for page (not working)

Count

Count number of pages in database


:q [:find (count ?n)
   :where
   [?n :node/title _]]

:q [:find (count ?n) :where [?n :node/title _]]

:q [:find (count ?n) :where [?n :node/title _]]

Count Blocks in database (not working)


:q [:find (pull ?e [
    :node/title 
    :block/string 
    :block/children 
    {:block/children ...}
])  
:where [?e :node/title]]

Count blocks under a parent

:q [:find (count ?x)
    :where 
      [?e :block/uid "F1aQG0uDB"]
      [?e :block/children ?x]
      ]

:q [:find (count ?x) :where [?e :block/uid "F1aQG0uDB"][?e :block/children ?x] ]

Show last 5 edited pages - Radar (not working)

:q [:find (max 5 ?PageName)
   :where
   [?n :node/title ?PageName]]

:q [:find ?et ?t ?e ?o  :where 
    [?e :node/title "What People Are Saying"]
    [?x :block/order ?o] 
    [?e :edit/time ?et]
    [?x :block/string ?t] ]

:q [:find ?et ?id ?t 
    :where
    [?n :node/title ?t]
    [?n :edit/time ?et]
    [?n :block/uid ?id]
    [(sort ?t)]]
    (sort-by val > ?et )

:q [:find ?et ?id ?t 
    :in $ %
    (max 5 ?et)
    :where
    [?n :node/title ?t]
    [?n :edit/time ?et]
    [?n :block/uid ?id]]

Show last edited block on page




:q [:find ?edit
    :where 
        [?e :node/title "quotes"]
        [?e :block/children ?x]
        [?x :block/string ?s] 
        [?x :edit/time ?edit]
        [?x :block/uid ?r]      
    ]

:q [:find ?r :where [?e :node/title "quotes"][?e :block/children ?x] [?x :block/string ?s][?x :edit/time ?edit] [?x :block/uid ?r]
]

Search for word in a specific namespace

:q [:find ?title, ?s, ?r
    :where 
        [?e :node/title ?title]
        [(re-matches #"(?i)\b.*(Book/).*" ?title)]
        [?e :block/children ?x]
        [?x :block/string ?s] 
        [(re-matches #"(?i)\b.*(Tags::).*" ?s)]
        [?x :block/uid ?r]      
    ]

Slider Value (not working)

[:find (pull ?parent [:block/uid :block/string])
             :where
             [?block :block/uid "${childUid}"]
             [?parent :block/children ?block]]
:q [:find ?v
    :where
    [?block :block/uid "NZWwYoU7d"]
    [?block :block/props ?v]]

:q [:find ?v :where [?block :block/uid "NZWwYoU7d"][?block :block/props ?v]]

Find all Blocks With Versions



:q [:find ?s, ?vs, ?r
    :where 
        [?e :node/title ?title]
        [?e :block/children ?x]
        [?x :block/string ?s] 
        [?x :vc/blocks ?vs]
        [?x :block/uid ?r]      
    ]
((gl6aYr6zV)) ((7XCWISPg5))
:q [:find ?s
    :where 
    [?block :block/uid "7XCWISPg5"]
    [?block :block/string ?s]
    [?block :vc/blocks ?v]]

testversions

version 2

Referenced in

July 18th, 2021

Useful Roam Tips Any query like {and: [[A]] [[B]] } can be replaced by using [[A+B]] then loading that page when needed