I want to basic count the number of records in my indexedDB database.
Currently my code looks like
Javascript
var transaction = db.transaction(["data"], "readonly");
var objectStore = transaction.objectStore("data");
var cursor = objectStore.openCursor();
var count = objectStore.count();
console.log(count);
I would love for this to say output just 3, but instead i get.
Output
IDBRequest {onerror: null, onsuccess: null, readyState: "pending", transaction: IDBTransaction, source: IDBObjectStore…}
error: null
onerror: null
onsuccess: null
readyState: "done"
result: 3
source: IDBObjectStore
transaction: IDBTransaction
__proto__: IDBRequest
Which is correct but I just want it to say 3 not loads of other stuff.
Bring back record count with a little less code:
var store = db.transaction(['trans']).objectStore('trans');
var count = store.count();
count.onsuccess = function() {
console.log(count.result);
}
Try something like this:
var transaction = db.transaction(["data"], "readonly");
var objectStore = transaction.objectStore("data");
var count = objectStore.count();
count.onsuccess = function() {
console.log(count.result);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With