How to use couchdb-python to call a view with a list of keys?

29 views
Skip to first unread message

Rémy Hubscher

unread,
Aug 1, 2014, 8:58:17 AM8/1/14
to couchdb...@googlegroups.com
Hello,

As of today I am doing this like so: https://github.com/spiral-project/daybed/pull/188/files#diff-8a9dcc556b8b8f869c6aa419ddc643deR61

    models = []
    for principal in principals:
        models += [d.value for d in views.models(self._db)[principal].rows]

How can I call directly the views using keys=principals?

Something equivalent to:

    models = [d.value for d in views.models(self._db)[*principals].rows]

Thank you very much,

Rémy

Dirkjan Ochtman

unread,
Aug 1, 2014, 9:08:51 AM8/1/14
to couchdb...@googlegroups.com
On Fri, Aug 1, 2014 at 2:58 PM, Rémy Hubscher <hubsch...@gmail.com> wrote:
> models = []
> for principal in principals:
> models += [d.value for d in views.models(self._db)[principal].rows]
>
> How can I call directly the views using keys=principals?
>
> Something equivalent to:
>
> models = [d.value for d in views.models(self._db)[*principals].rows]

You can generally pass a keys keyword argument to view, so I think
something like this should work:

models = [d.value for d in views.models(self._db, keys=principals).rows

Cheers,

Dirkjan
Reply all
Reply to author
Forward
0 new messages