diff --git a/CHANGELOG.md b/CHANGELOG.md index fe8a012..fc81aa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Org-roam also now does not resolve symlinks. This significantly speeds up cache ### 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. - [#1109](https://github.com/org-roam/org-roam/pull/1109) Org-roam now does not resolve symlinks. diff --git a/org-roam-compat.el b/org-roam-compat.el index a275818..f0a8cfc 100644 --- a/org-roam-compat.el +++ b/org-roam-compat.el @@ -41,8 +41,6 @@ "org-roam 1.0.0") (define-obsolete-function-alias 'org-roam-sql 'org-roam-db-query "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 "org-roam 1.0.0") (define-obsolete-function-alias 'org-roam-show-graph 'org-roam-graph-show diff --git a/org-roam-db.el b/org-roam-db.el index c67ddf6..d4c3d3a 100644 --- a/org-roam-db.el +++ b/org-roam-db.el @@ -55,7 +55,7 @@ (declare-function org-roam-buffer--update-maybe "org-roam-buffer") ;;;; 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. 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.") ;;;; 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 () "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." (unless (and (org-roam-db--get-connection) (emacsql-live-p (org-roam-db--get-connection))) - (let* ((db-file (org-roam-db--get)) - (init-db (not (file-exists-p db-file)))) - (make-directory (file-name-directory db-file) t) - (let ((conn (emacsql-sqlite3 db-file))) + (let ((init-db (not (file-exists-p org-roam-db-location)))) + (make-directory (file-name-directory org-roam-db-location) t) + (let ((conn (emacsql-sqlite3 org-roam-db-location))) (set-process-query-on-exit-flag (emacsql-process conn) nil) (puthash (expand-file-name org-roam-directory) conn @@ -200,7 +195,7 @@ the current `org-roam-directory'." ;;;;; Initialization (defun org-roam-db--initialized-p () "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])) 0))) @@ -213,7 +208,7 @@ the current `org-roam-directory'." (defun org-roam-db-clear () "Clears all entries in the Org-roam cache." (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)) (org-roam-db-query `[:delete :from ,table])))) @@ -257,9 +252,9 @@ Insertions can fail when there is an ID conflict." (condition-case nil (progn (org-roam-db-query - [:insert :into ids - :values $v1] - ids) + [:insert :into ids + :values $v1] + ids) t) (error (unless (listp ids) @@ -286,10 +281,10 @@ Insertions can fail if the key is already in the database." (type (car ref))) (condition-case nil (progn - (org-roam-db-query - [:insert :into refs :values $v1] - (list (vector key file type))) - t) + (org-roam-db-query + [:insert :into refs :values $v1] + (list (vector key file type))) + t) (error (lwarn '(org-roam) :error (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 (buffer-file-name (buffer-base-buffer)))) (if (not (file-exists-p file-path)) - (org-roam-db--clear-file file-path) - ;; save the file before performing a database update - (when-let ((buf (find-buffer-visiting file-path))) - (with-current-buffer buf - (save-buffer))) - (org-roam--with-temp-buffer file-path - (emacsql-with-transaction (org-roam-db) - (org-roam-db--update-meta) - (org-roam-db--update-tags) - (org-roam-db--update-titles) - (org-roam-db--update-refs) - (when org-roam-enable-headline-linking - (org-roam-db--update-ids)) - (org-roam-db--update-links))))) + (org-roam-db--clear-file file-path) + ;; save the file before performing a database update + (when-let ((buf (find-buffer-visiting file-path))) + (with-current-buffer buf + (save-buffer))) + (org-roam--with-temp-buffer file-path + (emacsql-with-transaction (org-roam-db) + (org-roam-db--update-meta) + (org-roam-db--update-tags) + (org-roam-db--update-titles) + (org-roam-db--update-refs) + (when org-roam-enable-headline-linking + (org-roam-db--update-ids)) + (org-roam-db--update-links))))) (defun org-roam-db-build-cache (&optional force) "Build the cache for `org-roam-directory'. If FORCE, force a rebuild of the cache from scratch." (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) ;; To initialize the database, no-op if already initialized (let* ((gc-cons-threshold org-roam-db-gc-threshold) diff --git a/tests/test-org-roam.el b/tests/test-org-roam.el index 94b11b5..8b94797 100644 --- a/tests/test-org-roam.el +++ b/tests/test-org-roam.el @@ -49,7 +49,7 @@ (defun test-org-roam--teardown () (org-roam-mode -1) - (delete-file (org-roam-db--get)) + (delete-file org-roam-db-location) (org-roam-db--close)) (describe "org-roam--str-to-list"