Shan
Shan

Reputation: 121

PouchDB on Hybrid Cordova App Not working

Am new to Hybrid app development, Am using Cordova v5, Ionic and PouchDB for my app. It seems everything works fine on Ionic serve command, but any operation on PouchDB seems to be not working on actual devices running Android Lollipop.

Am explicitly specifying 'WebSQL' when creating pouchDB object. I don't know whether Am missing any steps.

Here is the code

 var houselst = JSON.parse('<some json string>');

new PouchDB('SH_HouseVisitDB', { adapter: 'websql' }).destroy().then(function () {
            return new PouchDB('SH_HouseVisitDB');
        }).then(function (db) {

      var doc = {
                    "_id": "houselist",
                    "items": houselst
                };

                //insert the doc to pouchDB
                db.put(doc);
                db.get('houselist').then(function (doc) {
                    vm.houselist = _.sortBy(doc.items, "name");
                    db.close();
                });
}

Any help will be greatly appreciated.

Upvotes: 0

Views: 536

Answers (2)

Shan
Shan

Reputation: 121

Thank you for the support.

Finally figured it out, We need to name the db with websql prefix. I found the solution from the following thread.

https://github.com/pouchdb/pouchdb/issues/1207

Upvotes: 0

nlawson
nlawson

Reputation: 11620

It's generally not advisable to try to use new PouchDB(...) as a promise for itself (e.g. new PouchDB(...).then(...)). That's an older style that we're moving away from because it causes issues in some Promise environments due to circular dependencies. Try doing var db = new PouchDB(...); and see if that helps!

Upvotes: 0

Related Questions