webcss / angular-indexedDB

An angularjs serviceprovider to utilize indexedDB with angular
149 stars 99 forks source link

How to create index on array element in indexeddb #11

Open a2prn opened 10 years ago

a2prn commented 10 years ago

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?

webcss commented 10 years ago

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

a2prn commented 10 years ago

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?

webcss commented 10 years ago

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

fredtma commented 8 years ago

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

codershop commented 7 years ago

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