mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(internal): move org-roam.db default location (#1164)
Move the default location of `org-roam.db` to the user's Emacs directory. This is a more sensible default: those who sync their Org files would not have the database synced over as well.
This commit is contained in:
@ -8,6 +8,7 @@ Org-roam also now does not resolve symlinks. This significantly speeds up cache
|
|||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
|
||||||
|
- [#1164](https://github.com/org-roam/org-roam/pull/1164) Org-roam now stores the database in the user's Emacs directory by default
|
||||||
- [#910](https://github.com/org-roam/org-roam/pull/910) Deprecate `company-org-roam`, using `completion-at-point` instead. To use this with company, add the `company-capf` backend instead.
|
- [#910](https://github.com/org-roam/org-roam/pull/910) Deprecate `company-org-roam`, using `completion-at-point` instead. To use this with company, add the `company-capf` backend instead.
|
||||||
- [#1109](https://github.com/org-roam/org-roam/pull/1109) Org-roam now does not resolve symlinks.
|
- [#1109](https://github.com/org-roam/org-roam/pull/1109) Org-roam now does not resolve symlinks.
|
||||||
|
|
||||||
|
@ -41,8 +41,6 @@
|
|||||||
"org-roam 1.0.0")
|
"org-roam 1.0.0")
|
||||||
(define-obsolete-function-alias 'org-roam-sql 'org-roam-db-query
|
(define-obsolete-function-alias 'org-roam-sql 'org-roam-db-query
|
||||||
"org-roam 1.0.0")
|
"org-roam 1.0.0")
|
||||||
(define-obsolete-function-alias 'org-roam--get-db 'org-roam-db--get
|
|
||||||
"org-roam 1.0.0")
|
|
||||||
(define-obsolete-function-alias 'org-roam--db-clear 'org-roam-db--clear
|
(define-obsolete-function-alias 'org-roam--db-clear 'org-roam-db--clear
|
||||||
"org-roam 1.0.0")
|
"org-roam 1.0.0")
|
||||||
(define-obsolete-function-alias 'org-roam-show-graph 'org-roam-graph-show
|
(define-obsolete-function-alias 'org-roam-show-graph 'org-roam-graph-show
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
(declare-function org-roam-buffer--update-maybe "org-roam-buffer")
|
(declare-function org-roam-buffer--update-maybe "org-roam-buffer")
|
||||||
|
|
||||||
;;;; Options
|
;;;; Options
|
||||||
(defcustom org-roam-db-location nil
|
(defcustom org-roam-db-location (expand-file-name "org-roam.db" user-emacs-directory)
|
||||||
"The full path to file where the Org-roam database is stored.
|
"The full path to file where the Org-roam database is stored.
|
||||||
If this is non-nil, the Org-roam sqlite database is saved here.
|
If this is non-nil, the Org-roam sqlite database is saved here.
|
||||||
|
|
||||||
@ -85,10 +85,6 @@ value like `most-positive-fixnum'."
|
|||||||
"Database connection to Org-roam database.")
|
"Database connection to Org-roam database.")
|
||||||
|
|
||||||
;;;; Core Functions
|
;;;; Core Functions
|
||||||
(defun org-roam-db--get ()
|
|
||||||
"Return the sqlite db file."
|
|
||||||
(or org-roam-db-location
|
|
||||||
(expand-file-name "org-roam.db" org-roam-directory)))
|
|
||||||
|
|
||||||
(defun org-roam-db--get-connection ()
|
(defun org-roam-db--get-connection ()
|
||||||
"Return the database connection, if any."
|
"Return the database connection, if any."
|
||||||
@ -101,10 +97,9 @@ Initializes and stores the database, and the database connection.
|
|||||||
Performs a database upgrade when required."
|
Performs a database upgrade when required."
|
||||||
(unless (and (org-roam-db--get-connection)
|
(unless (and (org-roam-db--get-connection)
|
||||||
(emacsql-live-p (org-roam-db--get-connection)))
|
(emacsql-live-p (org-roam-db--get-connection)))
|
||||||
(let* ((db-file (org-roam-db--get))
|
(let ((init-db (not (file-exists-p org-roam-db-location))))
|
||||||
(init-db (not (file-exists-p db-file))))
|
(make-directory (file-name-directory org-roam-db-location) t)
|
||||||
(make-directory (file-name-directory db-file) t)
|
(let ((conn (emacsql-sqlite3 org-roam-db-location)))
|
||||||
(let ((conn (emacsql-sqlite3 db-file)))
|
|
||||||
(set-process-query-on-exit-flag (emacsql-process conn) nil)
|
(set-process-query-on-exit-flag (emacsql-process conn) nil)
|
||||||
(puthash (expand-file-name org-roam-directory)
|
(puthash (expand-file-name org-roam-directory)
|
||||||
conn
|
conn
|
||||||
@ -200,7 +195,7 @@ the current `org-roam-directory'."
|
|||||||
;;;;; Initialization
|
;;;;; Initialization
|
||||||
(defun org-roam-db--initialized-p ()
|
(defun org-roam-db--initialized-p ()
|
||||||
"Whether the Org-roam cache has been initialized."
|
"Whether the Org-roam cache has been initialized."
|
||||||
(and (file-exists-p (org-roam-db--get))
|
(and (file-exists-p org-roam-db-location)
|
||||||
(> (caar (org-roam-db-query [:select (funcall count) :from titles]))
|
(> (caar (org-roam-db-query [:select (funcall count) :from titles]))
|
||||||
0)))
|
0)))
|
||||||
|
|
||||||
@ -213,7 +208,7 @@ the current `org-roam-directory'."
|
|||||||
(defun org-roam-db-clear ()
|
(defun org-roam-db-clear ()
|
||||||
"Clears all entries in the Org-roam cache."
|
"Clears all entries in the Org-roam cache."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (file-exists-p (org-roam-db--get))
|
(when (file-exists-p org-roam-db-location)
|
||||||
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
(dolist (table (mapcar #'car org-roam-db--table-schemata))
|
||||||
(org-roam-db-query `[:delete :from ,table]))))
|
(org-roam-db-query `[:delete :from ,table]))))
|
||||||
|
|
||||||
@ -257,9 +252,9 @@ Insertions can fail when there is an ID conflict."
|
|||||||
(condition-case nil
|
(condition-case nil
|
||||||
(progn
|
(progn
|
||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into ids
|
[:insert :into ids
|
||||||
:values $v1]
|
:values $v1]
|
||||||
ids)
|
ids)
|
||||||
t)
|
t)
|
||||||
(error
|
(error
|
||||||
(unless (listp ids)
|
(unless (listp ids)
|
||||||
@ -286,10 +281,10 @@ Insertions can fail if the key is already in the database."
|
|||||||
(type (car ref)))
|
(type (car ref)))
|
||||||
(condition-case nil
|
(condition-case nil
|
||||||
(progn
|
(progn
|
||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into refs :values $v1]
|
[:insert :into refs :values $v1]
|
||||||
(list (vector key file type)))
|
(list (vector key file type)))
|
||||||
t)
|
t)
|
||||||
(error
|
(error
|
||||||
(lwarn '(org-roam) :error
|
(lwarn '(org-roam) :error
|
||||||
(format "Duplicate ref %s in:\n\nA: %s\nB: %s\n\nskipping..."
|
(format "Duplicate ref %s in:\n\nA: %s\nB: %s\n\nskipping..."
|
||||||
@ -458,26 +453,26 @@ If the file exists, update the cache with information."
|
|||||||
(setq file-path (or file-path
|
(setq file-path (or file-path
|
||||||
(buffer-file-name (buffer-base-buffer))))
|
(buffer-file-name (buffer-base-buffer))))
|
||||||
(if (not (file-exists-p file-path))
|
(if (not (file-exists-p file-path))
|
||||||
(org-roam-db--clear-file file-path)
|
(org-roam-db--clear-file file-path)
|
||||||
;; save the file before performing a database update
|
;; save the file before performing a database update
|
||||||
(when-let ((buf (find-buffer-visiting file-path)))
|
(when-let ((buf (find-buffer-visiting file-path)))
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(save-buffer)))
|
(save-buffer)))
|
||||||
(org-roam--with-temp-buffer file-path
|
(org-roam--with-temp-buffer file-path
|
||||||
(emacsql-with-transaction (org-roam-db)
|
(emacsql-with-transaction (org-roam-db)
|
||||||
(org-roam-db--update-meta)
|
(org-roam-db--update-meta)
|
||||||
(org-roam-db--update-tags)
|
(org-roam-db--update-tags)
|
||||||
(org-roam-db--update-titles)
|
(org-roam-db--update-titles)
|
||||||
(org-roam-db--update-refs)
|
(org-roam-db--update-refs)
|
||||||
(when org-roam-enable-headline-linking
|
(when org-roam-enable-headline-linking
|
||||||
(org-roam-db--update-ids))
|
(org-roam-db--update-ids))
|
||||||
(org-roam-db--update-links)))))
|
(org-roam-db--update-links)))))
|
||||||
|
|
||||||
(defun org-roam-db-build-cache (&optional force)
|
(defun org-roam-db-build-cache (&optional force)
|
||||||
"Build the cache for `org-roam-directory'.
|
"Build the cache for `org-roam-directory'.
|
||||||
If FORCE, force a rebuild of the cache from scratch."
|
If FORCE, force a rebuild of the cache from scratch."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(when force (delete-file (org-roam-db--get)))
|
(when force (delete-file org-roam-db-location))
|
||||||
(org-roam-db--close) ;; Force a reconnect
|
(org-roam-db--close) ;; Force a reconnect
|
||||||
(org-roam-db) ;; To initialize the database, no-op if already initialized
|
(org-roam-db) ;; To initialize the database, no-op if already initialized
|
||||||
(let* ((gc-cons-threshold org-roam-db-gc-threshold)
|
(let* ((gc-cons-threshold org-roam-db-gc-threshold)
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
(defun test-org-roam--teardown ()
|
(defun test-org-roam--teardown ()
|
||||||
(org-roam-mode -1)
|
(org-roam-mode -1)
|
||||||
(delete-file (org-roam-db--get))
|
(delete-file org-roam-db-location)
|
||||||
(org-roam-db--close))
|
(org-roam-db--close))
|
||||||
|
|
||||||
(describe "org-roam--str-to-list"
|
(describe "org-roam--str-to-list"
|
||||||
|
Reference in New Issue
Block a user