Hi @anon63144152, great question. I’m generally a fan of more atomic notes, so I would probably keep it to one file per query and then refer to them individually.
Of course, if the two queries depend on each other, or would always be together, then it might make sense to keep them in the same file.
I think I am going to have to go for one query in each JS file as I can’t get two queries in the same file to run. I would ideally like to add some inline JS snippets in the JS file as well but not been able to make those work either. Baby steps. Lots of reading to do.
But brilliant idea. Loving the paths it is taking my mind along.
Tried a couple of different solutions but always get some (varying) error messages.
I have the following dataview query:
TABLE WITHOUT ID Schlagwort, map(rows, (r) ="* " + link(r.file.link, r.title) + "<br>" + " (" + r.kategorie + ")") AS Einträge
FROM !"bibliothek"
WHERE file.path !=this.file.path
FLATTEN file.tags as Schlagwort
GROUP BY Schlagwort
WHERE econtains(this.file.etags, Schlagwort)
It works absolutely fine when put directly into a note. When put into a separate note and called (in the active note) via
Which will not execute within javascript either, or more correct it’ll not produce any sensible output. Remember that inline dataviewjs query is kind of surrounded by dv.span() in order to produce its output.
So if you change the file to include to something like:
Regarding the double DQL queries to be executed, that’s another matter it seems. There is an extra dataview before the second query, which makes it not compile, and give an error message on the console. But even with that fixed, it’s a little tricky to get it to work properly.
There are concurrency issues related to what runs when, and also related to how the dv.execute (or dv.query which I also tested) and the other dv.functions() calls are executed and hook into the DOM. At least, when I added the javascript above, two dv.header() calls, and the two dv.execute() the order got messed up, and only one of the two queries (seemingly random which one) was executed.
My full javascript-file
dv.span(
moment(dv.current().file.day.toISODate())
.diff(moment('2022-11-14'), 'years')
.toLocaleString('en-en') +
" years / " +
moment(dv.current().file.day.toISODate())
.diff(moment('2022-11-14'), 'days')
.toLocaleString('en-en')
+ " days" )
dv.header(2, "First query")
dv.execute(`
TABLE
file.tags as Tags1
WHERE file.tags
WHERE file.cday = this.file.day
OR file.mday = this.file.day
SORT file.mtime desc
LIMIT 10
`); /* */
dv.header(2, "Second query")
dv.execute(`
TABLE
file.tags as Tags2 , file.cday
WHERE file.tags
SORT file.mtime desc
LIMIT 10
`);
So I’m thinking it’s not wise to include too much of this stuff, especially in the context of calling through dv.view(). I’ve never experience this order issue, or stuff being left out when doing it directly within dataviewjs.