In How to use IndexedDB count method with composite keys? I learned how to filter for single attributes. So far, so good, but now I need to sort and filter at the same time.
My object store is filled with these objects:
os.put({feed_id:1,id:1,title:"foofoo",time:111});
os.put({feed_id:1,id:2,title:"foobar",time:112});
os.put({feed_id:1,id:3,title:"foobaz",time:113});
os.put({feed_id:3,id:1,title:"bazfoo",time:114});
os.put({feed_id:3,id:2,title:"bazbar",time:115});
os.put({feed_id:3,id:3,title:"bazbaz",time:116});
os.put({feed_id:1,id:4,title:"foofoo",time:122});
os.put({feed_id:1,id:5,title:"foobar",time:121});
os.put({feed_id:1,id:6,title:"foobaz",time:120});
os.put({feed_id:3,id:4,title:"bazfoo",time:119});
os.put({feed_id:3,id:5,title:"bazbar",time:118});
os.put({feed_id:3,id:6,title:"bazbaz",time:117});
I have two indices set on the object store, one (idx_feedid) has the keyPath feed_id
, which allows me to get all the objects with a specific feed id using openCursor, and one (idx_ts) with keyPath ["id","feed_id","time"]
.
The problem is that iterating over the results of idx_feedid gives me the results without ordering on the timestamp. In SQL I'd easily do a SELECT * FROM feeditems WHERE feed_id=3 ORDER BY time DESC
, but how does one do this in IndexedDB?
And how can I limit the results returned to achieve pagination? In essence I'd need something like MySQLs LIMIT 0,10
/LIMIT 10,10
/...