Return-Path: Delivered-To: apmail-incubator-couchdb-commits-archive@locus.apache.org Received: (qmail 73192 invoked from network); 29 Jun 2008 17:16:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Jun 2008 17:16:27 -0000 Received: (qmail 98662 invoked by uid 500); 29 Jun 2008 17:16:28 -0000 Delivered-To: apmail-incubator-couchdb-commits-archive@incubator.apache.org Received: (qmail 98633 invoked by uid 500); 29 Jun 2008 17:16:28 -0000 Mailing-List: contact couchdb-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-dev@incubator.apache.org Delivered-To: mailing list couchdb-commits@incubator.apache.org Received: (qmail 98624 invoked by uid 99); 29 Jun 2008 17:16:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Jun 2008 10:16:28 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Jun 2008 17:15:35 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 50C7611153 for ; Sun, 29 Jun 2008 17:15:25 +0000 (GMT) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Apache Wiki To: couchdb-commits@incubator.apache.org Date: Sun, 29 Jun 2008 17:15:25 -0000 Message-ID: <20080629171525.8682.45326@eos.apache.org> Subject: [Couchdb Wiki] Update of "ServeurDeVue" by BenoitC X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification. The following page has been changed by BenoitC: http://wiki.apache.org/couchdb/ServeurDeVue The comment on the change is: traduction démarrée New page: #language fr Une simple introduction au Serveur de vue de CouchDB. == Le serveur de vue == CouchDB délègue le calcul des ["Vues"] à des serveurs de requêtes externes. Il communique avec eux à travers l'entrée/sortie standard à travers un protocole simple à base de lignes. Le serveur de requêtes par défaut est en en Javascript, fonctionnant via Mozilla !SpiderMonkey. Vous pouvez utiliser d'autre languages en modifiant la propriété ''language'' d'un document design ou l'entête Content-Type d'une vue temporaire. CouchDB delegates computation of ["Views"] to external query servers. It communicates with them over standard input/output, using a very simple, line-based protocol. The default query server is written in Javascript, running via Mozilla !SpiderMonkey. You can use other languages by setting a MIME type in the ''language'' property of a design document or the Content-Type header of a temporary view. Design documents that do not specify a ''language'' property are assumed to be of type ''text/javascript'', as are ad hoc queries that are ''POST''ed to ''_temp_view'' without a ''Content-Type'' header. To register query servers with CouchDB, add a line for each server to ''couch.ini''. The basic syntax is: {{{ [Couch Query Servers] text/javascript=/usr/local/bin/couchjs -f /usr/local/share/couchdb/server/main.js text/ruby=/wherever/couchobject/bin/couch_ruby_view_requestor }}} == Basic API == This shows you how the view server implementation for your language should behave. If in doubt, look at the ''share/server/main.js'' file in your CouchDB source tree for reference. CouchDB launches the view server and starts sending commands. The server responds according to its evaluation of the commands. There are only three commands the view server needs to understand. === reset === This resets the state of the view server and makes it forget all previous input. If applicable, this is the point to run garbage collection. CouchDB sends: {{{ ["reset"]\n }}} The view server responds: {{{ true\n }}} === add_fun === When creating a view, the view server gets sent the view function for evaluation. The view server should parse/compile/evaluate the function he receives to make it callable later. If this fails, the view server returns an error. CouchDB might store several functions before sending in any actual documents. CouchDB sends: {{{ ["add_fun", "function(doc) { map(null, doc); }"]\n }}} When the view server can evaluate the function and make it callable, it returns: {{{ true\n }}} If not: {{{ {"error": "some_error_code", "reason": "error message"}\n }}} === map_doc === When the view function is stored in the view server, CouchDB starts sending in all the documents in the database, one at a time. The view server calls the previously stored functions one after another with the document and stores its result. When all functions have been called, the result is returned as a JSON string. CouchDB sends: {{{ ["map_doc", {"_id":"8877AFF9789988EE","_rev":46874684684,"field":"value","otherfield":"othervalue"}]\n }}} If the function above is the only function stored, the views server answers: {{{ [[[null, {"_id":"8877AFF9789988EE", "_rev":46874684684, "field":"value", "otherfield":"othervalue"}]]]\n }}} That is, an array with the result for every function for the given document. If a document is to be excluded from the View, the array should be empty. === reduce === If the view has a {{{reduce}}} function defined, CouchDB will enter into the reduce phase. The view server will receive a list of reduce functions and some map results on which it can apply them. The map results are given in the form {{{[[key, id-of-doc], value]}}}. CouchDB sends: {{{ ["reduce",["function(k, v) { return sum(v); }"],[[[1,"699b524273605d5d3e9d4fd0ff2cb272"],10],[[2,"c081d0f69c13d2ce2050d684c7ba2843"],20],[[null,"foobar"],3]]] }}} @@ Is there any guarantee on the ordering? The example appears unordered (null trailing) The view-server answers: {{{ [33] }}} Note that even though the view server receives the map results in the form {{{[[key, id-of-doc], value]}}}, the function may receive them in a different form. For example, the JavaScript view-server applies functions on the list of keys and the list of values. === rereduce === === log === At any time, the view-server may send some information that will be saved in CouchDB's log file. This is done by sending a special object with just one field, {{{log}}}, on a separate line. The view-server sends {{{ {"log":"A kuku!"} }}} CouchDB answers nothing. The following line will appear in {{{couch.log}}}, mutatis mutandum: {{{ [Sun, 22 Jun 2008 22:51:25 GMT] [info] [<0.72.0>] Query Server Log Message: A kuku! }}} If you use the JavaScript view-server, you achieve this effect by calling the function {{{log}}} in your view. To do the same thing in ClCouch, call {{{logit}}}. == Implementations == * [http://svn.apache.org/repos/asf/incubator/couchdb/trunk/share/server/main.js JavaScript] (CouchDB native) * [http://common-lisp.net/cgi-bin/darcsweb/darcsweb.cgi?r=submarine-cl-couch;a=summary Common Lisp] * [http://jan.prima.de/~jan/plok/archives/93-CouchDb-Views-with-PHP.html PHP] * [http://theexciter.com/articles/couchdb-views-in-ruby-instead-of-javascript Ruby] * [http://couchdb-python.googlecode.com/svn/trunk/couchdb/view.py Python]