Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specifying idProperty in dbConfig for IndexedDB prevents store from being created... #160

Closed
ddolga opened this issue Oct 13, 2015 · 1 comment

Comments

@ddolga
Copy link

ddolga commented Oct 13, 2015

In dstore/db/IndexedDB the idProperty is specified inside the store object:

 var dbConfig = {
            version: 1,
            name: "testwarn-db",
                options: {
                    idProperty: "chkSum",
                    chkSum: {
                        indexed: true
                    }
                }
            }
        }

This is where the constructor method looks for it:

 if (!db.objectStoreNames.contains(storeName)) {
                                var idProperty = storeConfig.idProperty || 'id';
                                var idbStore = db.createObjectStore(storeName, {
                                    keyPath: idProperty,
                                    autoIncrement: storeConfig[idProperty] &&
                                    storeConfig[idProperty].autoIncrement || false
                                });

However later on when it scans the store for indexes:

 for (var index in storeConfig) {
                                if (!idbStore.indexNames.contains(index) && index !== 'autoIncrement'
                                   // && index !== "idProperty" // hack to get to work
                                    && storeConfig[index].indexed !== false) {
                                  idbStore.createIndex(index, index, storeConfig[index]);
                                }
                            }

an error is thrown in idbStore.createIndex(index, index, storeConfig[index]) : "third parameter is not an object". This is because its passing the idProperty into the createIndex method. I had to modify the code to also check that index !== "idProperty" in order to get this to work.

@lxndr
Copy link

lxndr commented Jan 5, 2016

Got same problem. I'm trying to make a composite keyPath and write it like so

const dbConfig = {
  version: 1,
  stores: {
    answers: {
      idProperty: ['attempt', 'task'],
      attempt: {
      },
      task: {
        indexed: false
      }
    }
  }
}

It creates indexes 'idProperty' and 'attempt' instead of single 'attempt'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants