mirror of
https://github.com/org-roam/org-roam
synced 2025-08-29 14:33:29 -05:00
catch duplicate IDs during DB insertion
This commit is contained in:
@@ -281,39 +281,45 @@ If UPDATE-P is non-nil, first remove the file in the database."
|
|||||||
(aliases (org-entry-get (point) "ROAM_ALIASES"))
|
(aliases (org-entry-get (point) "ROAM_ALIASES"))
|
||||||
(tags org-file-tags)
|
(tags org-file-tags)
|
||||||
(refs (org-entry-get (point) "ROAM_REFS")))
|
(refs (org-entry-get (point) "ROAM_REFS")))
|
||||||
(org-roam-db-query
|
(condition-case err
|
||||||
[:insert :into nodes
|
(progn
|
||||||
:values $v1]
|
|
||||||
(vector id file level pos todo priority
|
|
||||||
scheduled deadline title))
|
|
||||||
(when tags
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into tags
|
|
||||||
:values $v1]
|
|
||||||
(mapcar (lambda (tag)
|
|
||||||
(vector file id (substring-no-properties tag)))
|
|
||||||
tags)))
|
|
||||||
(when aliases
|
|
||||||
(org-roam-db-query
|
|
||||||
[:insert :into aliases
|
|
||||||
:values $v1]
|
|
||||||
(mapcar (lambda (alias)
|
|
||||||
(vector file id alias))
|
|
||||||
(split-string-and-unquote aliases))))
|
|
||||||
(when refs
|
|
||||||
(setq refs (split-string-and-unquote refs))
|
|
||||||
(let (rows)
|
|
||||||
(dolist (ref refs)
|
|
||||||
(if (string-match org-link-plain-re ref)
|
|
||||||
(progn
|
|
||||||
(push (vector file id (match-string 2 ref) (match-string 1 ref)) rows))
|
|
||||||
(lwarn '(org-roam) :warning
|
|
||||||
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref)))
|
|
||||||
(when rows
|
|
||||||
(org-roam-db-query
|
(org-roam-db-query
|
||||||
[:insert :into refs
|
[:insert :into nodes
|
||||||
:values $v1]
|
:values $v1]
|
||||||
rows)))))))))
|
(vector id file level pos todo priority
|
||||||
|
scheduled deadline title))
|
||||||
|
(when tags
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into tags
|
||||||
|
:values $v1]
|
||||||
|
(mapcar (lambda (tag)
|
||||||
|
(vector file id (substring-no-properties tag)))
|
||||||
|
tags)))
|
||||||
|
(when aliases
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into aliases
|
||||||
|
:values $v1]
|
||||||
|
(mapcar (lambda (alias)
|
||||||
|
(vector file id alias))
|
||||||
|
(split-string-and-unquote aliases))))
|
||||||
|
(when refs
|
||||||
|
(setq refs (split-string-and-unquote refs))
|
||||||
|
(let (rows)
|
||||||
|
(dolist (ref refs)
|
||||||
|
(if (string-match org-link-plain-re ref)
|
||||||
|
(progn
|
||||||
|
(push (vector file id (match-string 2 ref)
|
||||||
|
(match-string 1 ref)) rows))
|
||||||
|
(lwarn '(org-roam) :warning
|
||||||
|
"%s:%s\tInvalid ref %s, skipping..."
|
||||||
|
(buffer-file-name) (point) ref)))
|
||||||
|
(when rows
|
||||||
|
(org-roam-db-query
|
||||||
|
[:insert :into refs
|
||||||
|
:values $v1]
|
||||||
|
rows)))))
|
||||||
|
(t
|
||||||
|
(lwarn '(org-roam) :error "Duplicate ID %s, skipping..." id))))))))
|
||||||
|
|
||||||
(defun org-roam-db-insert-node-data ()
|
(defun org-roam-db-insert-node-data ()
|
||||||
"Insert node data for headline at point into the Org-roam cache."
|
"Insert node data for headline at point into the Org-roam cache."
|
||||||
@@ -327,11 +333,15 @@ If UPDATE-P is non-nil, first remove the file in the database."
|
|||||||
(scheduled (org-roam-db-get-scheduled-time))
|
(scheduled (org-roam-db-get-scheduled-time))
|
||||||
(deadline (org-roam-db-get-deadline-time))
|
(deadline (org-roam-db-get-deadline-time))
|
||||||
(title (nth 4 heading-components)))
|
(title (nth 4 heading-components)))
|
||||||
(org-roam-db-query
|
(condition-case err
|
||||||
[:insert :into nodes
|
(org-roam-db-query
|
||||||
:values $v1]
|
[:insert :into nodes
|
||||||
(vector id file level pos todo priority
|
:values $v1]
|
||||||
scheduled deadline title)))))
|
(vector id file level pos todo priority
|
||||||
|
scheduled deadline title))
|
||||||
|
(t
|
||||||
|
(lwarn '(org-roam) :error
|
||||||
|
"Duplicate ID %s, skipping..." id))))))
|
||||||
|
|
||||||
(defun org-roam-db-insert-aliases ()
|
(defun org-roam-db-insert-aliases ()
|
||||||
"Insert aliases for node at point into Org-roam cache."
|
"Insert aliases for node at point into Org-roam cache."
|
||||||
@@ -365,7 +375,7 @@ If UPDATE-P is non-nil, first remove the file in the database."
|
|||||||
(save-match-data
|
(save-match-data
|
||||||
(if (string-match org-link-plain-re ref)
|
(if (string-match org-link-plain-re ref)
|
||||||
(progn
|
(progn
|
||||||
(push (vector file node-id (match-string 2 ref) (match-string 1 ref)) rows))
|
(push (vector file node-id (match-string 2 ref) (match-string 1 ref)) rows))
|
||||||
(lwarn '(org-roam) :warning
|
(lwarn '(org-roam) :warning
|
||||||
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref))))
|
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref))))
|
||||||
(org-roam-db-query [:insert :into refs
|
(org-roam-db-query [:insert :into refs
|
||||||
|
Reference in New Issue
Block a user