0

我想知道使用离子(角度)框架的混合应用程序是否可以进行以下配置:

如果我们使用带有 pouch db 适配器pouchdb-adapter-cordova-sqlite的cordova-sqlite-plugin,这应该可以工作,但它不适用于加密的适配器。

我面临的问题是打字稿无法转换。我不知道如何设置环境并使用密钥定义 sqlite-cipher 数据库。

这是一些示例打字稿代码:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import PouchDB from 'pouchdb';

import cordovaSqlitePlugin from 'pouchdb-adapter-cordova-sqlite';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {


  constructor(public navCtrl: NavController) {
    this.setUpPouch();
  }

  setUpPouch(){
    PouchDB.plugin(cordovaSqlitePlugin);
    let db = new PouchDB('dummypouch.db', { adapter: 'cordova-sqlite', key:"dummy_key"});
  }

}

我想知道是否有办法将密钥传递给 PouchDB 适配器而不破坏转译。

使转译失败的行:

let db = new PouchDB('dummypouch.db', { adapter: 'cordova-sqlite', key:"dummy_key"});

打字稿转译失败并显示以下消息:

[12:35:30]  typescript: src/pages/home/home.ts, line: 21 
            Argument of type '{ adapter: string; key: string; }' is not assignable to parameter of type 
            'DatabaseConfiguration'. Object literal may only specify known properties, and 'key' does not exist in type 
            'DatabaseConfiguration'. 


      L20:    PouchDB.plugin(cordovaSqlitePlugin);
      L21:    let db = new PouchDB('dummypouch.db', { adapter: 'cordova-sqlite', key:"dummy_key"});

Error: Failed to transpile program
    at new BuildError (/Users/santi/dummy_project/dummy_push_test/node_modules/@ionic/app-scripts/dist/util/errors.js:16:28)
    at /Users/santi/dummy_project/dummy_push_test/node_modules/@ionic/app-scripts/dist/transpile.js:159:20
    at new Promise (<anonymous>)
    at transpileWorker (/Users/santi/dummy_project/dummy_push_test/node_modules/@ionic/app-scripts/dist/transpile.js:107:12)
    at Object.transpile (/Users/santi/dummy_project/dummy_push_test/node_modules/@ionic/app-scripts/dist/transpile.js:64:12)
    at /Users/santi/dummy_project/dummy_push_test/node_modules/@ionic/app-scripts/dist/build.js:109:82
[12:35:30]  copy finished in 2.47 s 
4

1 回答 1

0

我回答我自己的问题以供参考。是的,只要我们不使用将类型添加到 typescript 的@types/pouchdb模块,这是可能的。

如果我们有它们,我们必须删除它并修复所有工作,而无需输入相关变量:

npm uninstall --save @types/pouchdb

我猜另一种选择是编写正确的类型并将它们包含在项目中......我没有这样做,所以我不确定。

于 2018-07-13T08:12:09.080 回答