Is there a way to get just top one row in IndexedDB? I could not find anything for it.
Using a cursor and not calling .continue() isn't a hack at all. It's the intended way. On of the main points of cursors is exactly that they let you only fetch the information that you need.
So no need to call transaction.abort()
Sort of a hack, but I believe that if you don't call continue() on the result object it will only process the first item.
Below is a quick example of querying with a cursor and only processing one result.
var db = _IndexedDatabase;
var trans = db.transaction(["Sites"], IDBTransaction.READ_ONLY);
var store = trans.objectStore("Sites");
var request = store.openCursor();
request.onsuccess = function (e)
{
var result = e.target.result;
if(!!result == false) { return; }
// Use result.value some how
// Comment out this line to process the first item only
//result.continue();
};
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