After testing pouchDB for my Ionic project, I tried to encrypt my data with crypto-pouch. I used the following code:
For init my database:
function initDB() { _db = new PouchDB('myDatabase', {adapter: 'websql'}); if (!_db.adapter) { _db = new PouchDB('myDatabase'); } return _db.crypto(password) .then(function(){ return _db; }); }
My function to map my documents:
function mapAllTypeOne(doc) { if (doc.type === 'type_one') { emit(doc._id); } }
To get all documents of type_one:
function getAllData { if (!_data) { return $q.when(_db.query(mapAllTypeOne, { include_docs: true})) .then(function(docs) { _data = docs.rows.map(function(row) { return row.doc; }); _db.changes({ live: true, since: 'now', include_docs: true}) .on('change', onDatabaseChange); return _data; }); } else { return $q.when(_data); } }
If I insert data of type_one, I can see it in my database and it is encrypted in the database. But I couldn’t see it in my list. After a reload (in the browser) or after closing and restarting the app (in android or iOS) the new data can be seen.
Whitout crypto-pouch the code is working well. Can anyone help me? Thanks in advance!