0

I'm trying to count how many records I have in a table using dexie.js

I try this: alert(db.table.count()); and browser return: [object Dexie.Promise]

If I use console.log(db.table.count()); the console say this:

Console log

This table has two records.. I believe that the _value item showing this result, but my problem is that I don't know how I can display this to the user.

I'm a PHP developer and I tried to make a loop and add the results, like this:

var var_quant = 0;
  db.table.orderBy("id").toArray()
  .then(list => {
    list.forEach(item => {
      console.log(`${item.name}`);  
      var_quant = var_quant + 1;
   });
})
.catch(error => { 
// handle error 
});
console.log(var_quant);

And the console displays the names of the bank, but does not add values ​​to the variable var_quant

Any suggestions on how to just get the number of records, in Mysql it was so easy :o.

1 Answer 1

0

Most Dexie methods are asynchronous, which (in Javascript) means they'll return Promises. You'll need to use a fulfillment handler or make it synchronous to access the actual number of elements.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.