How to call a _list function with pouchDb ?

55 views
Skip to first unread message

Yoann Diguet

unread,
Jun 30, 2015, 7:23:53 AM6/30/15
to pou...@googlegroups.com
Hi there,

I have a view that is accessible this way :

This gives me something dirty like this :
{"total_rows":5,"offset":0,"rows":[
{"id":"2015-06-24T00:58:52.387Z","key":["2015-06-24T00:58:52.387Z",0],"value":{"_id":"2015-06-24T00:58:52.387Z","_rev":"68-c6c58693cfc4a3c22c83fde26eeac897","type":"query","title":"sdfvsdf","content":"vsdvqd","projectId":"2015-06-24T00:42:45.247Z","opened":true,"uri":"sdfvsdf"},"doc":{"_id":"2015-06-24T00:58:52.387Z","_rev":"68-c6c58693cfc4a3c22c83fde26eeac897","type":"query","title":"sdfvsdf","content":"vsdvqd","projectId":"2015-06-24T00:42:45.247Z","opened":true,"uri":"sdfvsdf"}},
{"id":"2015-06-24T03:53:45.476Z","key":["2015-06-24T00:58:52.387Z",1],"value":{"_id":"2015-06-24T03:53:45.476Z","_rev":"117-4657fb9e59a2a4e835ff89a94c7f42ed","content":"<p>test <strong>sdgs</strong> dfg</p>\n","type":"answer","timestamp":"2015-06-24T03:53:45.476Z","projectId":"2015-06-24T00:42:45.247Z","queryId":"2015-06-24T00:58:52.387Z","accepted":true},"doc":{"_id":"2015-06-24T03:53:45.476Z","_rev":"117-4657fb9e59a2a4e835ff89a94c7f42ed","content":"<p>test <strong>sdgs</strong> dfg</p>\n","type":"answer","timestamp":"2015-06-24T03:53:45.476Z","projectId":"2015-06-24T00:42:45.247Z","queryId":"2015-06-24T00:58:52.387Z","accepted":true}},
{"id":"2015-06-24T05:30:20.010Z","key":["2015-06-24T00:58:52.387Z",1],"value":{"_id":"2015-06-24T05:30:20.010Z","_rev":"60-6b696d028ca6f47a5d0893df214cd4e9","content":"réponse à accepter","type":"answer","timestamp":"2015-06-24T05:30:20.010Z","projectId":"2015-06-24T00:42:45.247Z","queryId":"2015-06-24T00:58:52.387Z","accepted":true},"doc":{"_id":"2015-06-24T05:30:20.010Z","_rev":"60-6b696d028ca6f47a5d0893df214cd4e9","content":"réponse à accepter","type":"answer","timestamp":"2015-06-24T05:30:20.010Z","projectId":"2015-06-24T00:42:45.247Z","queryId":"2015-06-24T00:58:52.387Z","accepted":true}},
{"id":"2015-06-26T00:30:53.597Z","key":["2015-06-24T00:58:52.387Z",1],"value":{"_id":"2015-06-26T00:30:53.597Z","_rev":"4-2525914d882ddf72efa9ebb292c26b48","content":"<p>test kjh kjhkljh</p><p>sdf</p><blockquote><p>qsdv</p></blockquote><p>mji</p>","type":"answer","timestamp":"2015-06-26T00:30:53.598Z","projectId":"2015-06-24T00:42:45.247Z","queryId":"2015-06-24T00:58:52.387Z","accepted":false},"doc":{"_id":"2015-06-26T00:30:53.597Z","_rev":"4-2525914d882ddf72efa9ebb292c26b48","content":"<p>test kjh kjhkljh</p><p>sdf</p><blockquote><p>qsdv</p></blockquote><p>mji</p>","type":"answer","timestamp":"2015-06-26T00:30:53.598Z","projectId":"2015-06-24T00:42:45.247Z","queryId":"2015-06-24T00:58:52.387Z","accepted":false}}
]}


I also have a _list function in my design docs I can call this way :
This gives me something prettier like this :
[
  {
    "title": "sdfvsdf",
    "content": "vsdvqd",
    "opened": true,
    "answers": [
      {
        "_id": "2015-06-24T03:53:45.476Z",
        "content": "<p>test <strong>sdgs</strong> dfg</p>\u000a",
        "timestamp": "2015-06-24T03:53:45.476Z"
      },
      {
        "_id": "2015-06-24T05:30:20.010Z",
        "content": "réponse à accepter",
        "timestamp": "2015-06-24T05:30:20.010Z"
      },
      {
        "_id": "2015-06-26T00:30:53.597Z",
        "content": "<p>test kjh kjhkljh</p><p>sdf</p><blockquote><p>qsdv</p></blockquote><p>mji</p>",
        "timestamp": "2015-06-26T00:30:53.598Z"
      }
    ]
  }
]

... Which seems easier to bind with my angular app.

I can query my view using pouchDb like this :
$scope.db.query("data/queryAndAnswersByQueryId", {
startKey: ["2015-06-24T00:58:52.387Z",0],
endKey: ["2015-06-24T00:58:52.387Z",1],
include_docs: true
},
function (err, result) {
console.log(result);
}
);

... But I still don't know how to use my _list function called “queryView"...

I can't find any parameter allowing me to do this in the documentation... Am I missing something ?

Best regards,

Yoann

Marten de Vries

unread,
Jun 30, 2015, 9:59:09 AM6/30/15
to pou...@googlegroups.com
Hi Yoann,

If you only want to access the list function on your server, use a
simple XMLHttpRequest. In that case, there's no need to involve PouchDB.
If you want to run a list function against local data inside PouchDB, my
pouchdb-list plug-in might be of use:

- npm: http://npmjs.org/pouchdb-list
- documentation:
https://pythonhosted.org/Python-PouchDB/js-plugins.html#pouchdb-list-plug-in
- source code:
https://bazaar.launchpad.net/~marten-de-vries/python-pouchdb/0.x/view/head:/js/pouchdb-list
(npm install && npm run build to generate a normal js file.)

Hope that helps,
--
Marten de Vries

Op 30-06-15 om 13:23 schreef Yoann Diguet:
> --
> You received this message because you are subscribed to the Google
> Groups "PouchDB" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pouchdb+u...@googlegroups.com
> <mailto:pouchdb+u...@googlegroups.com>.
> To post to this group, send email to pou...@googlegroups.com
> <mailto:pou...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pouchdb/37a542f2-3f5d-4ebd-bdba-62b4f423107e%40googlegroups.com
> <https://groups.google.com/d/msgid/pouchdb/37a542f2-3f5d-4ebd-bdba-62b4f423107e%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Yoann Diguet

unread,
Jun 30, 2015, 3:42:15 PM6/30/15
to pou...@googlegroups.com
Hi Marten,

First of all, thank you for your answer !
I saw your api just after I posted this message, and even if I agree with you on the fact that a simple http request will do the job, it's just that I wanted to have the same calls on a remote server as I would do on a pouchDb database.
Anyway I tried you api, which seems pretty damn good as it is very well integrated with the rest of the api.
The only thing I didn't managed to do is to pass a startkey and and endkey to the request... yet :)

Thanks again for your help :D

Marten de Vries

unread,
Jun 30, 2015, 4:14:10 PM6/30/15
to pou...@googlegroups.com
When passing startkey/endkey as the second argument to db.list(), it
should pass them on to the underlying .query() call and thus work. Quite
similar to your $scope.db.query() example.

Op 30-06-15 om 21:42 schreef Yoann Diguet:
> > an email to pouchdb+u...@googlegroups.com <javascript:>
> > <mailto:pouchdb+u...@googlegroups.com <javascript:>>.
> > To post to this group, send email to pou...@googlegroups.com
> <javascript:>
> > <mailto:pou...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/pouchdb/37a542f2-3f5d-4ebd-bdba-62b4f423107e%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "PouchDB" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pouchdb+u...@googlegroups.com
> <mailto:pouchdb+u...@googlegroups.com>.
> To post to this group, send email to pou...@googlegroups.com
> <mailto:pou...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pouchdb/7e6b68ba-76e6-473a-b525-5dc7b3ba67d3%40googlegroups.com
> <https://groups.google.com/d/msgid/pouchdb/7e6b68ba-76e6-473a-b525-5dc7b3ba67d3%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
Marten de Vries
mart...@gmail.com

Yoann Diguet

unread,
Jun 30, 2015, 6:21:29 PM6/30/15
to pou...@googlegroups.com
ok thanks I'll try that
Reply all
Reply to author
Forward
0 new messages