Keeping two v2 separate databases

Hello everyone,

I would like to keep two separate org-roam v2 databases (work and personal stuff), and have a simple way to switch back and forth between them. Before I reinvent the wheel and write some elisp code, does anybody has a good way to do this?



It seems to be working V2 backlinks query does not find local database when running multiple org-roam environments · Issue #1482 · org-roam/org-roam · GitHub

Thank you. Yes, I saw that bit of the documentation but I am not sure if i understand how this is supposed to work. My first attempt was to do something like this:

(defun org-roam-swap-databases ()
  "Swap between work and personal org roam databases"
  (if (equal org-roam-directory "/home/julian/Documents/Notes/")
      (setq org-roam-directory "/home/julian/Documents/Personal/brain/")
      (setq org-roam-directory "/home/julian/Documents/Notes/"))


Which works, but requires that the database is synchronized after swapping, and I am not sure if this is the best do do it.

I don’t use .dir-locals.el but the documentation tells me this.

My understanding is that when you visit a file under the directory (and its sub-directories), Emacs swaps the variables – it may not be convenient if you want to sync or node-find before visiting such a file. But that seems to be the way?

The usual way to define directory-local variables is to put a file
named ‘.dir-locals.el’(1) in a directory. Whenever Emacs visits any
file in that directory or any of its subdirectories, it will apply the
directory-local variables specified in ‘.dir-locals.el’, as though they
had been defined as file-local variables for that file (*note File

Perhaps this modified @holtzermann17 snippet will help – I’ve been it in my config for some time now. Any suggestions to refine/improve this for v2? It works well on MacOS but it takes a couple tries to load on Windows.

#+begin_src emacs-lisp
;; see for these two functions for org-roam v1
(defvar org-roam-library
  `(,(concat "/Users/" (getenv "USER") "/Dropbox/org/org-roam/")
    ,(concat "/Users/" (getenv "USER") "/Dropbox/org/scratch/")
    ,(concat "/Users/" (getenv "USER") "/Dropbox/org/journal/")
    ,(concat "/Users/" (getenv "USER") "/Documents/powerbi-docs/")
(defun org-roam-checkout ()
  (let ((ctx org-roam-directory))
    (if (eq (length org-roam-library) 1)
        ;; Still go ahead and set the variable in this case!
        (progn (setq org-roam-directory (car org-roam-library)
                     org-roam-db-location (concat org-roam-directory "org-roam.db"))
               (message "You only have one choice for org-roam-directory defined."))
      (let ((lib (completing-read "Choose a volume: " org-roam-library)))
        (when lib
          (setq org-roam-directory lib
                org-roam-db-location (concat org-roam-directory "org-roam.db")))))
    ;; Assuming that the user changes context, let’s rebuild the cache
    ;; and prompt them to choose a new file in that context
    (when (not (eq ctx org-roam-directory))