couchdb-python
couchdb-python copied to clipboard
Wrapper Decorator for Reduce function
Fixes #105
Added a mutator function for the ViewField decorator which allows a reduce function to be set on a ViewField using a second decorator. This is just some sugar for creation a view with a map and reduce function using an explicit syntax.
Example
class Item(Document):
sku = TextField()
color = IntegerField()
stock = ViewField('people')
@stock.map
def map(doc):
yield doc['sku'], doc
@stock.reduce
def reduce(keys, values, rereduce):
if rereduce:
yield sum(values)
else:
yield len(values)