Dexie.js: multiple unique constrain

Created on 17 Apr 2017  路  3Comments  路  Source: dfahlander/Dexie.js

var db_me = new Dexie("UI_LANGUAGE");
db_me.version(1).stores({
  languages: "++id,&code,title", 
  words: "++id,language_id,index_name,title"
});

I want language_id and index_name to be unique together as a pair. Is that possible in Dexie ? & makes them unique but individually not as a pair.

Most helpful comment

You can index them both together and separate without having to use a new property

db_me.version(1).stores({
  languages: "++id,&code,title", 
  words: `
    ++id,
    language_id,
    &[language_id+index_name],
    index_name, 
    title
    `;
});

All 3 comments

It sounds like you want to use a compound index (http://dexie.org/docs/Compound-Index). Check also the browser limitations on that page

@nponiros but then when doing a where with only using language_id i get KeyPath language_id on object store words is not indexed.

For workaround im using another language_id_2 and using it to lookup in where query. is there any better way ?

You can index them both together and separate without having to use a new property

db_me.version(1).stores({
  languages: "++id,&code,title", 
  words: `
    ++id,
    language_id,
    &[language_id+index_name],
    index_name, 
    title
    `;
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

dmlzj picture dmlzj  路  3Comments

Script47 picture Script47  路  3Comments

dfahlander picture dfahlander  路  4Comments

CasperPas picture CasperPas  路  3Comments