Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created September 17, 2011 19:56
Show Gist options
  • Save boxxxie/1224297 to your computer and use it in GitHub Desktop.
Save boxxxie/1224297 to your computer and use it in GitHub Desktop.
 var couchapp = require('couchapp')
, path = require('path')
;
ddoc =
{ _id:'_design/app'
, rewrites :
[ {from:"/", to:'index.html'}
, {from:"/api", to:'../../'}
, {from:"/api/*", to:'../../*'}
, {from:"/*", to:'*'}
]
};
date_to_array = function(date){
return [date.getFullYear(),
(date.getMonth() + 1),
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds()];
};
//does not work
transactionDate = function(doc){
return date_to_array(new Date(doc.time.end));
};
ddoc.views = {};
ddoc.views.transactions_by_type = {
map : function (doc) {
/*works when defined here
transactionDate = function(doc){
return date_to_array(new Date(doc.time.end));
};*/
var key = [transactionDate(doc)];
emit(key, 1);
},
reduce: "_sum"
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment