Skip to content

Commit 12b329c

Browse files
committed
Fix for issue 76 (wrapping of view results in schema with include_docs=true). Also, removed the eager option, which has been obsoleted by include_docs.
--HG-- extra : convert_revision : svn%3A7a298fb0-333a-0410-83e7-658617cd9cf3/trunk%40154
1 parent dddaf8f commit 12b329c

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

ChangeLog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ http://couchdb-python.googlecode.com/svn/tags/0.6.0
1212
rev_or_exc)` tuples. See the docstring of that method for the details.
1313
* `schema.ListField` proxy objects now support the `__contains__()` and
1414
`index()` methods (issue 77).
15+
* The results of the `query()` and `view()` methods in the `schema.Document`
16+
class are now properly wrapped in objects of the class if the `include_docs`
17+
option is set (issue 76).
18+
* Removed the `eager` option on the `query()` and `view()` methods of
19+
`schema.Document`. Use the `include_docs` option instead, which doesn't
20+
require an additional request per document.
1521

1622

1723
Version 0.5

couchdb/schema.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -371,46 +371,37 @@ def store(self, db):
371371
db[self.id] = self._data
372372
return self
373373

374-
def query(cls, db, map_fun, reduce_fun, language='javascript',
375-
eager=False, **options):
374+
def query(cls, db, map_fun, reduce_fun, language='javascript', **options):
376375
"""Execute a CouchDB temporary view and map the result values back to
377376
objects of this schema.
378377
379378
Note that by default, any properties of the document that are not
380379
included in the values of the view will be treated as if they were
381-
missing from the document. If you'd rather want to load the full
382-
document for every row, set the `eager` option to `True`, but note that
383-
this will initiate a new HTTP request for every document, unless the
384-
``include_docs`` option is explitly specified.
380+
missing from the document. If you want to load the full document for
381+
every row, set the ``include_docs`` option to ``True``.
385382
"""
386383
def _wrapper(row):
387-
if eager:
388-
if row.doc is not None:
389-
return row.doc
390-
return cls.load(db, row.id)
384+
if row.doc is not None:
385+
return cls.wrap(row.doc)
391386
data = row.value
392387
data['_id'] = row.id
393388
return cls.wrap(data)
394389
return db.query(map_fun, reduce_fun=reduce_fun, language=language,
395390
wrapper=_wrapper, **options)
396391
query = classmethod(query)
397392

398-
def view(cls, db, viewname, eager=False, **options):
393+
def view(cls, db, viewname, **options):
399394
"""Execute a CouchDB named view and map the result values back to
400395
objects of this schema.
401396
402397
Note that by default, any properties of the document that are not
403398
included in the values of the view will be treated as if they were
404-
missing from the document. If you'd rather want to load the full
405-
document for every row, set the `eager` option to `True`, but note that
406-
this will initiate a new HTTP request for every document, unless the
407-
``include_docs`` option is explitly specified.
399+
missing from the document. If you want to load the full document for
400+
every row, set the ``include_docs`` option to ``True``.
408401
"""
409402
def _wrapper(row):
410-
if eager:
411-
if row.doc is not None:
412-
return row.doc
413-
return cls.load(db, row.id)
403+
if row.doc is not None: # include_docs=True
404+
return cls.wrap(row.doc)
414405
data = row.value
415406
data['_id'] = row.id
416407
return cls.wrap(data)

0 commit comments

Comments
 (0)