couchdb.client.ViewResults

Package couchdb :: Module client :: Class ViewResults |

# 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')
    >>> map_fun = '''function(doc) {
    ...     emit([doc.type, doc.name], doc.name);
    ... }'''
    >>> results = db.query(map_fun)

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='gotham', key=['City', 'Gotham City'], value='Gotham City'>]

    >>> del server['python-tests']

Instance Methods
__init__(self, view, options) x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
__repr__(self) repr(x) |
__getitem__(self, key) |
__iter__(self) |
__len__(self) |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
`list` | rows The list of rows returned by the view.
`int` or `NoneType` for reduce views | 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__`

Method Details

### __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)

Property Details

### rows The list of rows returned by the view. Get Method: unreachable.rows(self) - The list of rows returned by the view. Type: `list`

### total_rows The total number of rows in this view. This value is `None` for reduce views. Get Method: unreachable.total_rows(self) - The total number of rows in this view. Type: `int` or `NoneType` for reduce views

### offset The offset of the results from the first row in the view. This value is 0 for reduce views. Get Method: unreachable.offset(self) - The offset of the results from the first row in the view. Type: `int`