Search code examples
dexie

Is there any way to store objects as Compound index in dexie?


I`m using dexie wrapper library for indexedDB. I tried several ways to store objects in as Compound index in a table. Here is my table .

 db.version(1).stores({
        groupmap:"[g1+g2+g3],[g1+g2+g3+mdno],g1,g2,g3,active,mddate,mdno"
    });

Here is what I tried. But its not successful. and given error "DataError: Failed to execute 'only' on 'IDBKeyRange': The parameter is not a valid key. Error: Failed to execute 'only' on 'IDBKeyRange': The parameter is not a valid key"

 var g1Obj=new Object();
    g1Obj["id"]=1
    g1Obj["name"]="Breakfast"

    var g2Obj=new Object();
    g2Obj["id"]=1
    g2Obj["name"]="Burger"

    var g3Obj=new Object();
    g3Obj["id"]=1
    g3Obj["name"]="Chicken Burger"


             var obj = new Object();
                obj['g1']=g1Obj
                obj['g2']=g2Obj
                obj['g3']=g3Obj
                obj['mddate']=formatDateSecond4(new Date());
                obj['mdno']=formatDateSecond5(new Date());
                obj['active']=parseInt(1);

               db.transaction('rw',db.groupmap, function () {

                     db.groupmap.add(dataObj);
                     console.log ("[Group Map] Record saved to Local");

               }).catch(function (e) {
                      console.log ("[Group Map] Faild to save Record :"+e.message);

               });

Solution

  • Compound index is not supported on IE/Edge. Have you tried on other browser? You could also try applying IndexedDBShim that should make compound index work on IE/EDge. Haven't tested that myself but it claims to support it.