0

I have a simple Dexie table search function that I want to return the searched item after the searching code is actually run

function ReturnItemFromTable() {
  db.table1
   .where('field1')
   .equals('some value')
   .first(function(item) {
     return item
  }
}

So I know the 'return' in the above code is in the wrong place for the function to know it's supposed to be returned. But if I put it in the right place it gets returns before the table.where has had a chance to run and thus returns undefined.

Is there a way to get this ordering done right?

Thanks, Frank

  • Louis, I had already seen your answer because it came up while I was searching for answers prior to asking my question posted here. And while it is an educational source for a person like me who is somewhat new to the concepts of asynchronous programming, it was not at all an exact duplicate of my question. – FrankLeeKant Aug 30 '17 at 20:17

1 Answers1

0

Put a 'return' before 'db.table1' and your function will return a Promise that will resolve with the result.

To call it:

ReturnItemFromTable().then(function (result){
    alert('got ' + result);
}).catch (function (error) {
    alert (error);
});
David Fahlander
  • 5,058
  • 1
  • 20
  • 19