<p>How would I go about implementation the queries required for pagination?</p>

<p>Basically, when page 1 is requested, get the first 5 entries. For page 2, get the next 5 and so on.</p>

<p>I plan to use this via the couchdb-python module, but that shouldn't make any difference to the implementation.</p>

This is what I have came up with so far - to get the ids of all posts, then retrieve the actual items for the first x number of IDs..
It's not terribly efficient, but more so than retrieving all the posts, then throwing most of the away. That said, to my surprise, it seemed to run quite quickly - I ran the
```
posthelper.page()
```
method 100 times and it took about 0.5 seconds.
I didn't want to post this in the actual question, so it wouldn't influence the answers as much - here's the code:
```
```
allPostsUuid = """
function(doc) {
if(doc.type == 'post'){
    emit(doc._id, null);
}
}
"""

class PostsHelper:
    def __init__(self):
        server = Server(config.dbhost)
        db = server[config.dbname]
        return db

    def _getPostByUuid(self, uuid):
        return self.db.get(uuid)

    def page(self, number = 1):
        number -= 1 # start at zero offset
        start = number * config.perPage
        end = start + config.perPage

        allUuids = [
            x.key for x in self.db.query(allPostsUuid)
        ]
        ret = [
            self._getPostByUuid(x) for x in allUuids[start : end]
        ]

        if len(ret) == 0:
            raise Error404("Invalid page (%s results)" % (len(allUuids)))
        else:
            return ret
```
```