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"))
|
||||
(tags org-file-tags)
|
||||
(refs (org-entry-get (point) "ROAM_REFS")))
|
||||
(org-roam-db-query
|
||||
[:insert :into nodes
|
||||
: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
|
||||
(condition-case err
|
||||
(progn
|
||||
(org-roam-db-query
|
||||
[:insert :into refs
|
||||
[:insert :into nodes
|
||||
: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 ()
|
||||
"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))
|
||||
(deadline (org-roam-db-get-deadline-time))
|
||||
(title (nth 4 heading-components)))
|
||||
(org-roam-db-query
|
||||
[:insert :into nodes
|
||||
:values $v1]
|
||||
(vector id file level pos todo priority
|
||||
scheduled deadline title)))))
|
||||
(condition-case err
|
||||
(org-roam-db-query
|
||||
[:insert :into nodes
|
||||
:values $v1]
|
||||
(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 ()
|
||||
"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
|
||||
(if (string-match org-link-plain-re ref)
|
||||
(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
|
||||
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref))))
|
||||
(org-roam-db-query [:insert :into refs
|
||||
|
Reference in New Issue
Block a user