I'd like to know if the following configuration is even possible for a hybrid app using ionic (angular) framework:
This should work if we use the cordova-sqlite-plugin using a pouch db adapter, pouchdb-adapter-cordova-sqlite, but it doesn't with the encrypted one.
The problem I face is that typescript doesn't transpile. I don't know how to set up the environment and define a sqlite-cipher database with a key.
Here's some sample typescript code:
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"});
}
}
I'd like to know if there's a way to pass the key to the PouchDB adapter without breaking transpilation.
The line that makes transpiling fail:
let db = new PouchDB('dummypouch.db', { adapter: 'cordova-sqlite', key:"dummy_key"});
The typescript transpile fails with this message:
[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
I answer my own question for reference. Yes it is possible as long as we don't use the @types/pouchdb module that adds types to typescript.
In case we have them we have to remove it and fix everything to work without typing in the related variables:
Another option, I guess, is to write the proper types and include them in the project... I didn't do it so I am not certain.