In some notes I have completely identical dataview queries or completely identical set of metadata (with different values), is it possible to change the query syntax or metadata list for all notes at once?
For example a query looks like this
TABLE
url, channel, content_type, duration, my_score AS score
WHERE type = "video" and contains(content, [[]])
SORT file.name DESC
And the set of metadata like this
category::
producer::
type::
installed_version::
installed_on::
For example, I need to add another column to the query, and add tags:: to the metadata
dv.execute(TABLE url, channel, content_type, my_score AS score WHERE type = "video" and contains(content, [[]]) SORT file.name DESC);
but I still donât understand where to set the name of the view.js file that the obsidian note accesses
And is it necessary to use await in view.js or everything is fine ?
When you do dv.view("js/something") it does one of two things:
It looks in the folder js to see if there is a sub folder named something containing a view.js (and possibly a view.css) file. If this exists run that javascript file
It looks in the folder js for a file named something.js and executes it if found
Furthermore, depending on your script and whether that script does any file input/output (and not just looks in the cache which could be the case often), youâll need the await in front of the dv.view(). Especially if you do any await inside of the script, youâll definitively also need it on the outside.
Sadly, there seems to be a bug currently which could render at least inline awaited calls to dv.view() as empty. Not sure how or whether a dataviewjs code block is affected in the same view. Need to test that during the weekend.
Instead of doing dv.span(await dv.tryQuewry()) you should most likely do some variant of dv.table(). Take a look at the post below for a whimsical example on how to do the query and table output in a nice fashion with potential error handling.
Finally whatever you enter as parameters to dv.view() after the script is put into the input variable, and how youâll use it is depending on your needs. Here are three examples:
input = "Some file name" - Just identical to the given name
input = [ 1, 2, 3, 4] - The list of those four numbers
The final variant is for a compound object, and youâll get:
`input.file = âSome file nameâ
input.list = [1, 2, 3, 4]
Hopefully that clears it up a little. If in doubt, add console.log(input) at one of the first lines of your script, and check the Console tab in Developers Tools to see that the actual content of input became in your use case.
Furter variable interpolation is as normal for javascript.
That makes a little more sense to me, thank you.
I tried using your code to generate a table, I put it in view.js but I have an error related to await
my code querying the actual table
if (input == "video_content") {
const result= await dv.query(`
TABLE tags, dateformat(file.ctime, "DD"), url, duration, channel, my_score AS score WHERE type = "video" and contains(content, [[]]) SORT file.name DESC
`)
a bug I see in Obsidian
Evaluation Error: SyntaxError: await is only valid in async functions and the top level bodies of modules
at new Function ()
at DataviewInlineApi.view (plugin:dataview:18355:28)
at async eval (eval at (plugin:dataview), :1:54)
at async DataviewJSRenderer.render (plugin:dataview:18436:13)
Your query works in obsidian itself when I use ```dataviewjs and await inside it
but I would like to use it in an external view.js file to change the query text from one place, rather than searching all over obsidian for it