I have an object store "messages" with "timestamp" and "chat_id" fields inside it. I want to get all "chats" inside this object store ordered by "timestamp" field. As far as I see, I can't do it with IndexedDB only.
I can get them like this using WebDatabase:
SELECT * FROM messages GROUP BY chat_id ORDER BY timestamp
In IndexedDB:
- if I create compound index using ["chat_id", "timestamp"], records still won't be sorted by "timestamp" field. Instead they will be sorted by "chat_id" first. So that 2-year-old messages with "chat_id" == 1 will be preceding messages with "chat_id" == 2, written yesterday.
- if I create simple index of "chat_id" and get records from this index using "nextunique", same chat messages are sorted with primary key. In my case it's message "id".
Am I wrong? Is it possible to sort grouped selection in IndexedDB?
UPD: I want to get all chats "grouped" by chat_id and sort this selection by timestamp. So that newest chats will be the first.