Ionic PouchDb Sqlite plugin issue

2019-02-18 23:55发布

问题:

We are seriously exploring Ionic, PouchDb and CouchDb as a solution to one of our requirement where we need to build a mobile app which can provide offline sync functionality and also to be platform agnostic.

One of the other major requirement we have, that the data in offline mode would be persistence in nature and can grew more than 500 MB and since PouchDb is going to use IndexedDB / WebSQL adapters etc. to store data in offline mode, it has certain size limitation in mobile and web platform and also the data is not persistence in nature.

Then I came across this article in pouchdb site itself:

http://pouchdb.com/adapters.html

Where you can use SQLite plugin for Cordova and you can write something like:

To force the PouchDb to use SQLite plugin.

var db = new PouchDB('myDB', {adapter: 'websql'});

But when I test the code using following code to check whether WebSql adapter is using SQLite plugin or not, both in Android (chrome remote debugging) and web platform.

db.info().then(console.log.bind(console));

The sqlite_plugin is always returning false and also it is not creating any .db files. Though PouchDb and CouchDb sync is working fine.

Object {doc_count: 5, update_seq: 42, sqlite_plugin: false, websql_encoding: "UTF-8", db_name: "birthdays"…}
1.  adapter: "websql"
2.  auto_compaction: false
3.  db_name: "testDb"
4.  doc_count: 5
5.  sqlite_plugin: false
6.  update_seq: 42
7.  websql_encoding: "UTF-8"
8.  __proto__: Object
And also it mentioned

The SQLite Plugin does not currently pass the PouchDB test suite. It also tends to be slower than direct IndexedDB/WebSQL. We recommend avoiding the SQLite Plugin, unless you are hitting the 50MB storage limit in iOS or you require native or preloaded access to the database files.

I have used following command to install the SQLite plugin:

cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin.git

Here is Ionic version information: Click to see the Ionic version information currently using by me.

PouchDB version: 5.2.0

I would highly appreciate if someone can help me to solve this issue. Thanks in advance.

回答1:

There is a demo of a Cordova app using PouchDB and the SQLite Plugin. Mostly likely you just need to make sure that SQLite Plugin <script> is loaded before the PouchDB <script>.

That said, if your app data is seriously 500MB (half a GB!), I would recommend against using PouchDB. Especially if you are not using sync, then PouchDB has too much overhead with the revision structure and will run slowly.

You are probably better off directly using the SQLite Plugin. Hope that helps!