PouchDB + SQLite on ionic 2

时间:2016-05-07 14:50:54

标签: sqlite pouchdb

我遵循了PouchDB设置和SQLite的所有步骤。我正面临以下问题:

1)this._db.info()。then(console.log.bind(console)) - 显示适配器:websql,sqlite_plugin:false

Object
    adapter:"websql"
    auto_compaction:false
    db_name:"bakbak"
    doc_count:15
    sqlite_plugin:false
    update_seq:15
    websql_encoding:"UTF-8"

我不确定我做错了什么。

2)应用程序在Chrome上正常运行。在Firefox上它引发了一个错误:this.db.sync不是一个函数。我将其更改为PouchDB.sync然后错误消失了。为什么会这样?

3)在firefox和IE上进行上述更改后我得到了#34; EXCEPTION:错误:未捕获(在承诺中):错误:适配器丢失"。

此错误已解决:https://groups.google.com/forum/#!searchin/pouchdb/sqlite/pouchdb/-ROWHfB3Ty0/6qEfRkf6MTkJ

我试着按照这里的建议:Ionic PouchDb Sqlite plugin issue

但我没有在index.html中导入任何pouchdb库。它不在js文件夹中。我可以在node-modules文件夹中找到它。

<body>
<ion-app></ion-app>
<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>
<!-- Polyfill needed for platforms without Promise and Collection support   -->
<script src="build/js/es6-shim.min.js"></script>
<!-- Zone.js and Reflect-metadata  -->
<script src="build/js/angular2-polyfills.js"></script>
<!-- the bundle which is built from the app's source code -->
<script src="build/js/app.bundle.js"></script>
</body>

我进行了以下更改以启用sqlite2插件:

    <script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    var db;

    alert("window.cordova: " + window.cordova);
    alert("window.SQLitePlugin: " + window.SQLitePlugin);

    if (window.cordova && window.SQLitePlugin) { // because Cordova is platform specific and doesn't work when you run ionic serve               
        db = window.sqlitePlugin.openDatabase({ "name": "bakbak" }); //device - SQLite
        alert("device db (SQLite) loaded");
    } else {

        db = window.openDatabase("APSNetMobileDb", "1.0", "bakbak", 100 * 1024 * 1024); // browser webSql, a fall-back for debugging
        alert("browser db (WebSQL) loaded");
    }
    </script>

提醒显示cordova和sqlite未定义

1 个答案:

答案 0 :(得分:0)

&#34;缺少适配器&#34;是一个PouchDB错误,表明它无法找到传递给adapter构造函数的PouchDB。你拼错了吗?它应该是:var db = new PouchDB('dbname', {adapter: 'websql'})

OTOH它可能不是那样,因为我在输出sqlite_plugin:false中看到意味着SQLite插件未正确加载。

您可能想尝试SQLite Plugin 2,因为它是PouchDB支持方面最受支持的SQLite插件。否则,请确保已定义window.sqlitePlugin,因为这表明插件已正确加载。