0

Currently I am learning about javascript IndexedDB, and I found I cannot do complicated query when I use it. Now I want to make a select query like
"select * from table where indexA >= 'a' order by indexB ASC limit 10"

I tried to use
store.createIndex("indexA, indexB", ["indexA","indexB"])
and tried to make request like
store.index("indexA, indexB").openCursor(IDBKeyRange.lowerBound([1, "a"], true))
however the result only ordered according to indexA. Is there any way to do it?

PurkkaKoodari
  • 6,703
  • 6
  • 37
  • 58
Heng Liu
  • 5
  • 1

1 Answers1

1

You have to roll this yourself. There are basically two approaches:

  • Use an index on 'indexA' as you've done, open a cursor with lower bound 'a' and iterate, accumulate all the results, then sort by indexB, and pick the first 10.
  • Use an index on 'indexB', open a cursor and iterate, skipping any entries where indexA < 'a', and stop after 10 are encountered.

The linked topic (thanks, other Josh!) provides more detail.

Joshua Bell
  • 7,727
  • 27
  • 30