How to change the query or metadata in all notes at once?

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

The need to change queries like that is why stuff like dv.view() exists, where to can change the view script to your hearts content whenever you want.

A query in a note requires individual attention, either through manyal labour or through search-and-replace magic.

1 Like

can you show me how dv.view works ?
I haven’t found any proper documentation

I did it this way and it almost works, almost because the view is not like the table.
In the note I write

‘’‘dataviewjs
await dv.view(“Scripts”);
‘’’

In the view.js file which is in the Scripts folder I write

dv.span((await dv.tryQuery(TABLE url, channel, channel, content_type, my_score AS score WHERE type = "video" and contains(content, [[]])))))

and it gives me the answer not as a table, but as a list.

  1. How can I change the query in view.js to have a regular table as after the query via dataview?
  2. Why does it request view.js because I don’t specify the name of this file anywhere ?

After this code in view.js all works

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 ?

And I dont understand how to add second argument(input) in
dv.view(path, input)
I tryed names input1, input2 it wasnt work

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:

await dv.view("js/script", "Some file name")
await dv.view("js/script", [ 1, 2, 3, 4 ] )
await dv.view("js/script",  { "file" : "Some file name", "list": [ 1, 2, 3, 4 ])

The content of input in these cases would be:

  • 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.

1 Like

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