Ok I had to make myself literate in using the Common-Lisp library;
One good thing your tests have done is it has allowed me to understand the data-types and how they are used,
I think you have defined your constructor function wrongly – we have to define the arg list in the same way we get from the query – which is conveniently provided by the p-case destructive binding
Here’s the full corrected code -
(cl-defstruct (org-roam-node (:constructor org-roam-node-create)
(:constructor org-roam-node-create+
(id &optional file file-title level todo pos priority scheduled deadline
title properties olp atime mtime tags aliases refs))
(:copier nil))
"A heading or top level file with an assigned ID property."
file file-title file-hash file-atime file-mtime
id level point todo priority scheduled deadline title properties olp
tags aliases refs)
(defun test/org-roam-node-list ()
"Return all nodes stored in the database as a list of `org-roam-node's."
(let ((rows (org-roam-db-query
"SELECT
id,
file,
filetitle,
\"level\",
todo,
pos,
priority ,
scheduled ,
deadline ,
title,
properties ,
olp,
atime,
mtime,
'(' || group_concat(tags, ' ') || ')' as tags,
aliases,
refs
FROM
(
SELECT
id,
file,
filetitle,
\"level\",
todo,
pos,
priority ,
scheduled ,
deadline ,
title,
properties ,
olp,
atime,
mtime,
tags,
'(' || group_concat(aliases, ' ') || ')' as aliases,
refs
FROM
(
SELECT
nodes.id as id,
nodes.file as file,
nodes.\"level\" as \"level\",
nodes.todo as todo,
nodes.pos as pos,
nodes.priority as priority,
nodes.scheduled as scheduled,
nodes.deadline as deadline,
nodes.title as title,
nodes.properties as properties,
nodes.olp as olp,
files.atime as atime,
files.mtime as mtime,
files.title as filetitle,
tags.tag as tags,
aliases.alias as aliases,
'(' || group_concat(RTRIM (refs.\"type\", '\"') || ':' || LTRIM(refs.ref, '\"'), ' ') || ')' as refs
FROM nodes
LEFT JOIN files ON files.file = nodes.file
LEFT JOIN tags ON tags.node_id = nodes.id
LEFT JOIN aliases ON aliases.node_id = nodes.id
LEFT JOIN refs ON refs.node_id = nodes.id
GROUP BY nodes.id, tags.tag, aliases.alias )
GROUP BY id, tags )
GROUP BY id")))
(cl-loop for row in rows
collect (apply #'org-roam-node-create+ row))))
(advice-add 'org-roam-node-list :override #'test/org-roam-node-list)
What do we lose?
- Aliases - they would not work as intended.
EDIT
Sorry we cannot take directly from the p-case destructive bind
(cl-defstruct (org-roam-node (:constructor org-roam-node-create)
(:constructor org-roam-node-create+
(id &optional file file-title level todo point priority scheduled deadline
title properties olp file-atime file-mtime tags aliases refs))
(:copier nil))
"A heading or top level file with an assigned ID property."
file file-title file-hash file-atime file-mtime
id level point todo priority scheduled deadline title properties olp
tags aliases refs)
We need to adjust the name changes done inside that function
Overall this should be our new constructor definition