obsidian-db-folder icon indicating copy to clipboard operation
obsidian-db-folder copied to clipboard

[Bug]: `db.dataview.query()` Displays `object Promise` Instead of Successful Response

Open be-studio opened this issue 1 year ago • 5 comments

What happened?

I have an external JavaScript file that exports a function (taking db as an argument). Within that function a call is made to db.dataview.query. I am able to console log the successful promise response and want to try to return that within the DB Folder view using a column formula. However, instead of returning the successful response it displays object Promise. Even when I try to add logic to extract data that can meaningfully be displayed from the promise response it still displays object Promise. Is there a workaround, something I missed, or a bug? Please advise. Thank you.

Example of code involved

function getMileages(db) {
  db.dataview.query("TABLE mileage FROM #car-data SORT DESC")
  .then(response => {
    const mileages = response.value.values;
    console.log(mileages);  // This logs array of values correctly.
    return mileages[1];  // Does not display in DB Folder view, instead shows 'object Promise'
  })
  .catch(() => console.log("ERROR"));
}

module.exports = getMileages;

I have even tried:

async function getMileages(db) {
  try {
    const response = await db.dataview.query("TABLE mileage FROM #car-data SORT DESC");
    const mileages = response.value.values;
    console.log(mileages);  // This logs array of values correctly.
    return mileages[1];  // Does not display in DB Folder view, instead shows 'object Promise'
  } catch(err) {
    return;
  }
}

module.exports = getMileages;

Column Formula

${db.js.getMileages(db)}

Environment

Obsidian version 1.1.16* Obsidian DB Folder plugin version 3.3.2* Obsidian Dataview plugin version 0.5.55* Mac OS Ventura 13.2* Apple MacBook Pro M1 16GB RAM

  • Latest versions at time of posting this issue

What platform were you using?

Cross

Version of the plugin

3.3.2

Relevant log output

No response

Are you using the latest version of the plugin in your Obsidian vault?

  • [X] I have verified that I am on the latest version

Are you check if there is a similar issue?

  • [X] I have verified that there are not similar issues

be-studio avatar Mar 09 '23 10:03 be-studio

Just out of curiosity, what would happen if you await ed the formula? ${ await db.js.getMileages(db)}

donovanrost avatar Mar 16 '23 00:03 donovanrost

No luck @donovanrost , but thanks for the suggestion.

Further investigation reveals console logging does show the promise is being resolved and a correct response being generated in the background, but the DB folder table keeps displaying object Promise.

be-studio avatar Mar 16 '23 12:03 be-studio

Hello @be-studio , I will try to await your sample diretly with the Func() of dbfolder. Thanks for your testing!

RafaelGB avatar Mar 16 '23 12:03 RafaelGB

Thank you @RafaelGB for looking further into this. Much appreciated. If there is any other way I can assist, please let me know.

This is an excellent and extremely useful plugin you are developing...keep up the good work!

be-studio avatar Mar 16 '23 15:03 be-studio

Commit a761e981 I have tried this solution without much success, but I think it is the way. If anyone has any ideas or sees a bug in the testing branch, they are welcome.

RafaelGB avatar Mar 20 '23 22:03 RafaelGB