After testing pouchDB for my Ionic project, I tried to encrypt my data with crypto-pouch. But I have a problem with using design documents. I used the following code:
One of my design documents:
var allTypeOne = { _id: '_design/all_TypeOne', views: { 'alle_TypeOne': { map: function (doc) { if (doc.type === 'type_one') { emit(doc._id); } }.toString() } } };
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; });
// add a design document _db.put(allTypeOne).then(function (info) {
}).catch(function (err) {
} }
To get all documents of type_one:
function getAllData { if (!_data) { return $q.when(_db.query('all_TypeOne', { 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); } }
This code works without using crypto-pouch well, but if I insert the _db.crypto(…) no data is shown in my list. Can anyone help me? Thanks in advance!