I've been working on transitioning from websql to indexeddb, but I'm struggling to recreate the SELECT query: "SELECT * FROM tableA WHERE cid ='"+cid+"' AND hid IN("+hid+",1) ORDER BY hid DESC LIMIT 1";
function getMyData(e) {
var s ="";
var hid = "value1";
var cid = "value2";
var transaction = db.transaction(["table"], "readonly");
var store = transaction.objectStore("table");
var index = store.index("myIndex"); // myIndex was established during onupgradeneeded using ['hid','cid']
var request = index.openCursor(IDBKeyRange.only([hid, cid]));
request.onsuccess = function(e){
var cursor = e.target.result;
if(cursor){
s +="<h2>Key "+cursor.key+"</h2><p>";
for (var field in cursor.value){
s += field+"="+cursor.value[field]+"<br>";
}
s +="</p>"
cursor.continue();
}
document.querySelector("#mySpan").innerHTML = s;
}
}
I want to display the data when hid = value1 and cid = value2, but if the store index doesn't contain [value1,value2], I want to show the data from the store index [aDefaultValue,value2]. (where the default value is 1 in the sql statement). I attempted using upperbound, but it retrieves the index [value1(-1), value2] data rather than [1,value2] data.