I have an indexedDb that has following indexes
objectStore.createIndex('course', 'course', {unique: false});
objectStore.createIndex('year', 'year', {unique: false});
objectStore.createIndex('session', 'session', {unique: false});
objectStore.createIndex('rollnumber', 'rollnumber', {unique: false});
objectStore.createIndex('name', 'name', {unique: false});
Now I have a form that has fields for all the above indexes. The user fills the form and I have to filter the results according to whatever field user fills. So if the user only fills the course
and session
field then I have to return all objects that match the two indexes.
Relational version would be simple
SELECT * FROM college WHERE session = ? AND course = ?
I can prepare the query depending on what fields user filled. But in indexedDb I need to know the combination before hand, which is not possible for so many different possible combinations.
For the above case something like this will be required
objectStore.createIndex('courseSession', ['course', 'session'], {unique: false});
Which is all fine and dandy except this is not the only possible combination, user can fill any number of fields it wants to to narrow the result. So how do I accomplish this? I can't write 2^5 (or whatever) possible combinations of those 5 fields.
I found this question which is relevant. But it doesn't solve the problem that I don't know the combination that I will need, so I can't create an index in advance.
TL;DR: I don't know in advance what indexes I want to 'search' the datastore for so I can't create an index.