QUERY TOOLS

The Query Tools extension adds various tools on top of traditional Roam queries to make them more powerful

Installation

You could use the Copy Extension button below to individually install this extension. To install, just paste anywhere in your Roam graph and click "Yes, I Know What I'm Doing".

Manual Installation

If instead you prefer to manually install, first create a block with the text {{[[roam/js]]}} on any page in your Roam DB. Then, copy and paste this code block as a child of the block.

var existing = document.getElementById("roamjs-query-tools");
if (!existing) {
  var extension = document.createElement("script");
  extension.src = "https://roamjs.com/query-tools.js";
  extension.id = "roamjs-query-tools";
  extension.async = true;
  extension.type = "text/javascript";
  document.getElementsByTagName("head")[0].appendChild(extension);
}

Usage

The script supports the following configuration attributes, to be added in the [[roam/js/query-tools]] page:

  • Sort Blocks - (Optional) If set to 'True', sort the query results by blocks instead of pages.
  • Context - (Optional) The default value for Context for all queries. See below.

On expanded queries, there will be a sort icon that appears next to the results text. Clicking on the sort icon will make a sort menu visible to the user with the following options:

  • Sort By Page Title - This will sort all the query results in ascending alphabetical order of the page title.
  • Sort By Page Title Descending - This will sort all the query results in descending alphabetical order of the page title.
  • Sort By Word Count - This will sort all the query results in ascending order of the word count.
  • Sort By Word Count Descending - This will sort all the query results in descending alphabetical order of the word count.
  • Sort By Created Date - This will sort all the query results in ascending order that the page was created.
  • Sort By Created Date Descending - This will sort all the query results in descending order that the page was created.
  • Sort By Edited Date - This will sort all the query results in ascending order that the page was last edited.
  • Sort By Edited Date Descending - This will sort all the query results in descending order that the page was last edited.
  • Sort By Daily Note - This will sort all the query results in ascending order by Daily Note, followed by created date of non-daily note pages.
  • Sort By Daily Note Descending - This will sort all the query results in descending order by Daily Note, followed by created date of non-daily note pages.

To persist a particular sort on a query, create a child block with the Default Sort attribute. Valid values include each of the options above, minus the sort by prefix. For example, Default Sort:: Page Title.

To configure sorting by blocks on a single query instead of on all queries in your DB, add the Sort Blocks attribute as a child to the specific query.

Randomization

Sometimes we have queries with hundreds of results and want to return a random element from that query. Returning random results from multiple queries could lead to serendipitous connections. To return a random result from a query, add theRandom attribute as a child block of the query. Set the value to the number of random results you'd like returned from the query. For example, to return three random results from a query, add the following block as a child to the query:

Random:: 3

Context

By default, query results only display the most nested block in the result. To display more context in a given query, add the Context attribute as a child block of the query. Set the value to the number of levels you'd like displayed, or Top to display full context. For Example, to always show two more levels of context to each query result, add the following block as a child to the query:

Context:: 2

Demo

Contributors

This extension is brought to you by RoamJS! If you are facing any issues reach out to support@roamjs.com or click on the chat button on the bottom right. If you get value from using this extension, consider sponsoring RoamJS by clicking on the button below!

ROAMJS DIGEST

Add your email below to stay up to date on all RoamJS features, fixes, and news!

Other Extensions