Dataview of current folder - can I use FROM or is WHERE ok?

What I’m trying to do

I’m displaying tables of notes within the same folder (and sub-folders) as the dataview block.

Things I have tried

I’ve found from other discussions that I can use

TABLE blah
WHERE startswith(file.folder, this.file.folder) AND other_criteria

But I’m replacing code that was

TABLE blah
FROM "explicit/folder/name"
WHERE other_criteria

My gut feel is somehow that I’d like to keep my FROM separate from my WHERE; in which case it’d be nice to be able to somehow have FROM "$= this.file.folder" or some other magic syntax.

Is that possible? Does it really matter in any way to Dataview, would it make the query more efficient or something? Or should I just use WHERE?

Hi Korny,
I think either of those would work just as well. The advantage of the first one, is that you can put it in a template and it will just work wherever it is. With the second one you would need to edit it to make it work for a new place if it was templated. So For me, because I am a bit of a template nerd, I would do the first one.

Cheers,
Peter.

I tend to use WHERE a lot as I feel it’s more flexible. There is however a slight difference in efficiency (at least theoretically), and that is that when using FROM first you’re allowing dataview to limit the data set it’s working on at an earlier level, whereas the WHERE works initially on the full data set of notes.

So given a larger note base, or doing stuff like flattening whichever lists/tasks there are across the whole vault and then doing a WHERE vs limiting by using FROM in the start might drastically change your efficiency.

Then again, before doing javascript to read file contents, you’re most likely working with the cached metadata so it might not matter in most cases. And you most likely don’t have a vault being large enough for this to be noticed.

I’ve actually moved to dataviewjs - I was doing the same thing over and over in templates, and from reading another thread I found I could reuse javascript scripts rather than repeating them, which is much nicer for fiddling.

Also in javascript I can go back to using WHERE effectively:

function logs(current) {
    let pages = dv.pages(`"${current.file.folder}"`).where(page => page.kind == 'LogFile');
    dv.list(pages.file.link);
}
logs(input)

then in my view:

await dv.view("/Meta/scripts/project_logs",dv.current())
2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.