I am trying to move from websql to indexeddb but can't seem to replicate 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 created onupgradeneeded from ['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'd like to show the data if hid = value1 and cid = value2 but if the store index does not contain [value1,value2], I'd like to display data from store index [aDefaultValue,value2]. (the default value being 1 in the sql statement). I tried upperbound but this returns the index [value1(-1), value2] data rather than [1,value2] data.