Class ViewResults
object --+
|
ViewResults
Representation of a parameterized view (either permanent or temporary)
and the results it produces.
This class allows the specification of key, startkey, and
endkey options using Python slice notation.
>>> server = Server('http://localhost:5984/')
>>> db = server.create('python-tests')
>>> db['johndoe'] = dict(type='Person', name='John Doe')
>>> db['maryjane'] = dict(type='Person', name='Mary Jane')
>>> db['gotham'] = dict(type='City', name='Gotham City')
>>> code = '''function(doc) {
... map([doc.type, doc.name], doc.name);
... }'''
>>> results = db.query(code)
At this point, the view has not actually been accessed yet. It is accessed
as soon as it is iterated over, its length is requested, or one of its
rows, total_rows, or offset properties are accessed:
>>> len(results)
3
You can use slices to apply startkey and/or endkey options to the
view:
>>> people = results[['Person']:['Person','ZZZZ']]
>>> for person in people:
... print person.value
John Doe
Mary Jane
>>> people.total_rows, people.offset
(3, 1)
Use plain indexed notation (without a slice) to apply the key option.
Note that as CouchDB makes no claim that keys are unique in a view, this
can still return multiple rows:
>>> list(results[['City', 'Gotham City']])
[<Row id=u'gotham', key=[u'City', u'Gotham City'], value=u'Gotham City'>]
|
__init__(self,
view,
options)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
|
|
|
|
|
|
|
|
|
|
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__setattr__ ,
__str__
|
list
|
rows
The list of rows returned by the view.
|
int
|
total_rows
The total number of rows in this view.
|
int
|
offset
The offset of the results from the first row in the view.
|
Inherited from object :
__class__
|
__init__(self,
view,
options)
(Constructor)
|
|
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
- Overrides:
object.__init__
- (inherited documentation)
|
__repr__(self)
(Representation operator)
|
|
repr(x)
- Overrides:
object.__repr__
- (inherited documentation)
|