开发者

How to combine show and list functions in CouchDB?

I am trying to study CouchDB. Is there a way to use list functions in a show function, or vice versa开发者_JAVA技巧? For example, can I call some list function to render a document in its show function? Or call show(id) to render a list if ids in a list function?


As of now, I do not believe there is a direct way to do so.

However, you are able to re-use code (including templates) via CommonJS modules. Although you won't be able to call a _list through a _show function, you can simulate the reverse, and use the same templates/code from a _show in your _list response.


I believe what you are trying to do is render child entities together with their parent entity. This can be achieved by having the view pass both the parent and the children to the list function in a particular order.

There is an example in the The Definitive Guide for a scenario with multiple parent entities, each having child entities. For the simpler case of only one parent, the view may emit the parent entity followed by its children, and the list function may go along the lines of:

parent_entity = getRow();
/* ... make parent_repr ... */
send(parent_repr);
while (child_entity = getRow()) {
    /* ... make child_repr ... */
    send(child_repr);
}

Thus, you do not have to have a separate show function for the parent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜