How to create a link to a org-roam search?

Right now you would write your own SQL query for the db. Getting the SQL right isn’t the most fun, but once you have it you’re done.

org-mode helpfully has an elisp: link-type that will run any elisp command you use as its ‘path’, eg. elisp:(find-file "Elisp.org") See here

Running a query is actually pretty easy if you look in a function like org-roam-db--get-titles (do C-h f in emacs), or just look through the source code in org-roam-db.el.

Once you decide on a query you can either link to it or else use a code block in org-mode to write the code and display the results (see here, this is why org-mode is awesome). Something like:

#+BEGIN_SRC elisp
(org-roam-db-query 
  [:select [from] :from links :where (= to $s1)] "path/to/NoteA")

#+END_SRC

That will return all of the filenames to notes that link to Note A. To add more filters (Notes K, M, tags) you can add more SQL or elisp until you get what you want. You can also add things that will output them as file: links to make them functional and navigable if you want (sidenote: I’d be interested if this would work for literally any language that has a SQLite package, if people wanted to rabidly avoid learning elisp).

There should probably be an easier way to do all of this in the future. I would guess it would mostly involve the graph abilities people are working on :slight_smile:

EDIT: I should add that org-roam-db--connected-component also exists, and may suit your needs!

1 Like