nolanlawson / cordova-plugin-sqlite-2

Native SQLite database API for Cordova/PhoneGap/Ionic, modeled after WebSQL (UNMAINTAINED)
https://nolanlawson.com/2016/04/10/introducing-the-cordova-sqlite-plugin-2/
Apache License 2.0
168 stars 28 forks source link

No data persistence on iOS PouchDB #47

Closed Sin- closed 7 years ago

Sin- commented 7 years ago

As the title suggests, I can't seem to make my data persistent on iOS with PouchDB. PouchDB with the websql adapter seems to work fine, I can create an item and get it back but if I quit the app, and launch it back, my data is gone. I was previously using cordova-plugin-sqlite before discovering this one. I thought this was my problem and replaced it with this one, but the problem is still here, do you have any idea? Thanks!

pablomaurer commented 7 years ago

maybe wrong adapter gets used? I thought you could check it with db.info();

nolanlawson commented 7 years ago

Yes, can you provide more steps to reproduce? Also db.adapter is another way to figure out which adapter you're using.

tomexa commented 7 years ago

Actually, I followed this nice tutorial step by step and then replaced the original sqlite plugin with this one: http://gonehybrid.com/how-to-use-pouchdb-sqlite-for-local-storage-in-your-ionic-app/ I specifically ask my db to use websql with: _db = new PouchDB('birthdays', {adapter: 'websql'}); I have not yet tested the db.info(), I'll test it this evening.

Sin- commented 7 years ago

Here is my return of db.info(): { "do_count":" 2, "update_seq": 2, "websl_encoding": "UTF-8", "db_name": "contacts", "auto-compaction": false, "adapter": "websql" }

Shouldn't there be a sqlite_plugin field? I also used this to make sure sqlite is working, and it does nothing... document.addEventListener('deviceready', function() { window.sqlitePlugin.echoTest(function() { console.log('ECHO test OK'); }); }); I think it evens crashes the app, so it seems the sqlite plugin is in fact not wroking...

Sin- commented 7 years ago

Ok, I fixed the persistence issue I had a problem with my get function. But I'm still bothered by this missing sqlite_plugin field missing. It surely means I'm not using sqlite. Do you think I can rely solely on the persistence of PouchDB with websql or cordova sqlite is preferred? This is going to be an offline contacts manager and losing the data would be critical...

pablomaurer commented 7 years ago

websql is persistent but there is a 5mb limit on ios. Yes, should be something with sqlite. try remove the plugin, remove the platform ios. add again platform ios and add again the plugin.

tomexa commented 7 years ago

I tried removing the platform, reinstalling it, removing the plugin and the platform, reinstalling the platform and the plugin in every order imaginable. Still no sqlite_plugin field...

pablomaurer commented 7 years ago

Then try to create the local db with the option {adapter: 'cordova-sqlite'}

Sin- commented 7 years ago

Just tried it, nothing changes... I checked I included the pouchdb.cordova-sqlite.js file after pouchdb.js file in the index and everything seems good but I still don't have the sqlite_plugin field in the db.info(). It must be a SQLite problem, but I just can't see why it doesn't work...

nolanlawson commented 7 years ago

@Sin- I just checked that tutorial; it is out of date and provides instructions for PouchDB 5. In PouchDB 6 you now have to use pouchdb-adapter-cordova-sqlite.

db.info() will not tell you if you're using cordova-sqlite anymore, but db.adapter will. Sorry for the confusion.

nolanlawson commented 7 years ago

Please follow these directions: https://github.com/nolanlawson/pouchdb-adapter-cordova-sqlite

Sin- commented 7 years ago

Indeed! I already followed these instructions, but never thought about printing the output of dB.adapter as I read everywhere it wouldn't work, but it does! It returns 'cordova-sqlite'. Thanks for the help now I can continue the development =)

nolanlawson commented 7 years ago

Awesome. Thanks!