angular-indexedDB icon indicating copy to clipboard operation
angular-indexedDB copied to clipboard

How to create index on array element in indexeddb

Open a2prn opened this issue 11 years ago • 5 comments

I have an object.

var _data = { teacher : { name : "Mack", subject : "Maths" }, Student : [{ stud_name : "Alex", stud_id : 1 },{ stud_name : "Jack", stud_id : 2 },{ stud_name : "Mark", stud_id : 3 }] };

I want to create index on array element of object. i.e, I want to create an index on stud_name. Is it possible to create such type of index in indexeddb?

a2prn avatar Jan 04 '14 06:01 a2prn

Please refer to indexeddb documentation https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB to learn how to create indexes (on array elements).

webcss avatar Jan 04 '14 14:01 webcss

Thanks webcss, I am able to create index on array element if I have object like this,

var data = { teacher : { name : "Mack", subject : "Maths" }, Student : ["Mark" , "John"] }

by using: store.createIndex("indexname","data .Student", {unique:false,multiEntry:true});

But I am not able to create index on array of object element.

eg: var data = { teacher : { name : "Mack", subject : "Maths" }, Student : [{ studname : "Alex", stud_id : 1 },{ stud_name : "Jack", stud_id : 2 },{ stud_name : "Mark", stud_id : 3 }] };

In object above data object has Student array, which has multiple objects. And I want to create index on array of object (data.Student.stud_name). Is it possible to create such type of index?

a2prn avatar Jan 11 '14 04:01 a2prn

As proposed here https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB#Structuring_the_database it definitly is possible to solve your problem.

webcss avatar Mar 04 '14 07:03 webcss

Has there been a solution to this? The specified link does not say much

fredtma avatar Jan 14 '16 15:01 fredtma

It currently is not possible to create an index from a property of an object in an array of objects. There was an issue filed for the spec that you can follow here: https://github.com/w3c/IndexedDB/issues/35

codershop avatar Jun 14 '17 16:06 codershop