Last active
August 29, 2015 14:13
-
-
Save marten-de-vries/f938337b94773112d7b5 to your computer and use it in GitHub Desktop.
Revisions
-
marten-de-vries revised this gist
Jan 21, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ How to run ---------- 1. Get index.js and test.js in the same (otherwise empty) directory. 2. Execute the following commands: ``` -
marten-de-vries revised this gist
Jan 21, 2015 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ How to run ---------- 1. get index.js and test.js in the same (otherwise empty) directory. 2. Execute the following commands: ``` npm install pouchdb memdown pouchdb-abstract-mapreduce evaljs node test.js ``` -
marten-de-vries created this gist
Jan 21, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ var abstractMapReduce = require('pouchdb-abstract-mapreduce'); var evaljs = require('evaljs'); var methods = abstractMapReduce({ name: 'evaljsviews', mapper: function (mapFunDef, emit) { var env = new evaljs.Environment({emit: emit}); return env.gen('(' + mapFunDef + ')')(); }, reducer: function (reduceFunDef) { // TODO }, ddocValidator: function (ddoc, viewName) { // TODO } }); exports.evaljsQuery = methods.query; exports.evaljsViewCleanup = methods.viewCleanup; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ var PouchDB = require('pouchdb'); var plugin = require('./index'); PouchDB.plugin(plugin); var db = new PouchDB('test', {db: require('memdown')}); db.bulkDocs([ { _id: '_design/test', views: { test: { map: function (doc) { // a relatively 'complicated' view for (var i = 0; i < doc.roles.length; i++) { var role = doc.roles[i]; if (role.indexOf('a') === -1) { emit(role); } } }.toString() } } }, { roles: ['b', 'c', 'a'] }, { roles: ['e', 'f', 'b'] } ]).then(function () { return db.evaljsQuery('test/test'); }).then(function (resp) { console.log(resp.rows.map(function (item) { return item.key; // [ 'b', 'b', 'c', 'e', 'f' ] })); });