webcss / angular-indexedDB

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

Possible bugs on "each" feature #38

Open ghost opened 10 years ago

ghost commented 10 years ago

I believe "each" has some bugs

  1. I get errors like "object is not a function" because of line 449 callback(e.target.result);
  2. No results because of line 446 if(!e.target.result){

Maybe

...
req.onsuccess = req.onerror = function(e) {
    $rootScope.$apply(function(){
        if(!e.target.result){
            d.resolve(e.target.result);
        }
        callback(e.target.result);
    });
};
...

should be something like

..
req.onsuccess = req.onerror = function(e) {
    $rootScope.$apply(function(){
        if(e.target.result){
            d.resolve(e.target.result);
        }
    });
};
...

with my suggestion things seem to work better but I have no idea is it correct.

What I have is something like

Setup:

var store = db.createObjectStore('fooBar', {keyPath: 'fooBarId', autoIncrement:true});
store.createIndex('keyIndex', ['foo','bar'], {unique:false});

Query:

var store = $indexedDB.objectStore('fooBar');

var key = [ fooValue, barValue ];

var query = $indexedDB.queryBuilder()
                .$index('keyIndex')
                .$eq(key)
                .compile();

return store.each(query).then(function(cursor) {
    if (cursor.value) {
        return cursor.value;
    }
});
ghost commented 10 years ago

Ok now when I look closer, what I posted above is incorrect since I was using example from README but the actual method signature has changed since

erik-seifert commented 10 years ago

Can you please provide a correct example