shreyj
shreyj

Reputation: 1807

Can I specify a 'unique together' constraint in an IndexedDb objectstore?

I use IndexedDb to store some data for offline use. I need to make sure that in an objectstore no two objects have same certain attributes.

For ex the object in my object store which stores details of movies are as such:

{title : value1, director : value2, writer : value3, revenue : value4} 

Now, when I add data I dont't want 2 objects with same {title , director, writer}. From what I have explored, I can create an index on a field and specify unique = true for this index. This way no 2 objects can have the same value for this particular field. But, is there a way to specify these 'unique together' fields on an objectstore.

Upvotes: 3

Views: 343

Answers (1)

Kristof Degrave
Kristof Degrave

Reputation: 4180

As I see in the latest version of the specs, this should be possible. You can do this by passing an array as keypath. I haven't tried it my self, but this should be the solution. I would advise you to use the nightly build of firefox to test this. This will give you the greatest possibility to have a working implementation.

objectstore.createIndex("indexname", ["title", "director", "writer"], { unique: true });

Upvotes: 3

Related Questions