(refactor): org-roam-db--clear-file pull tables from schemata (#613)

Programatically pull tables from schemata, rather than manually
specifying.
This commit is contained in:
N V
2020-05-13 02:14:46 -04:00
committed by GitHub
parent fca1777648
commit e0cefa7377

View File

@ -192,25 +192,15 @@ the current `org-roam-directory'."
(org-roam-db-query [:delete :from links]) (org-roam-db-query [:delete :from links])
(org-roam-db-query [:delete :from refs]))) (org-roam-db-query [:delete :from refs])))
(defun org-roam-db--clear-file (&optional filepath) (defun org-roam-db--clear-file (&optional filepath)
"Remove any related links to the file at FILEPATH. "Remove any related links to the file at FILEPATH.
This is equivalent to removing the node from the graph." This is equivalent to removing the node from the graph."
(let* ((path (or filepath (let ((file (file-truename (or filepath
(buffer-file-name))) (buffer-file-name (buffer-base-buffer))))))
(file (file-truename path))) (dolist (table (mapcar #'car org-roam-db--table-schemata))
(org-roam-db-query [:delete :from files (org-roam-db-query `[:delete :from ,table
:where (= file $s1)] :where (= ,(if (eq table 'links) 'from 'file) $s1)]
file) file))))
(org-roam-db-query [:delete :from links
:where (= from $s1)]
file)
(org-roam-db-query [:delete :from titles
:where (= file $s1)]
file)
(org-roam-db-query [:delete :from refs
:where (= file $s1)]
file)))
;;;;; Insertion ;;;;; Insertion
(defun org-roam-db--insert-links (links) (defun org-roam-db--insert-links (links)