From peddy at common-lisp.net Sat Mar 1 19:19:17 2008 From: peddy at common-lisp.net (peddy) Date: Sat, 1 Mar 2008 14:19:17 -0500 (EST) Subject: [clouchdb-cvs] CVS clouchdb/public_html Message-ID: <20080301191917.8933F3203A@common-lisp.net> Update of /project/clouchdb/cvsroot/clouchdb/public_html In directory clnet:/tmp/cvs-serv28981/public_html Modified Files: index.html style.css Log Message: - Updated docs with complex view key info - Updated examples with complex view examples --- /project/clouchdb/cvsroot/clouchdb/public_html/index.html 2008/02/18 03:16:01 1.16 +++ /project/clouchdb/cvsroot/clouchdb/public_html/index.html 2008/03/01 19:19:16 1.17 @@ -219,8 +219,8 @@
NB: If you try these examples I suggest also viewing the results via CouchDb's bulit-in HTML UI - at http://localhost:8888/_utils/browse/index.html, - (or http://localhost:5984/_utils/browse/index.html + at http://localhost:5894/_utils/browse/index.html, + (or http://localhost:8888/_utils/browse/index.html if you're using ClouchDb versions prior to 7.2), of course you'll need to adjust the URL for the actual CouchDb server and port in use. @@ -302,11 +302,11 @@ ;; Get revision information for this document (formatted for legibility) CLOUCHDB-USER> (get-document "someid" :revision-info t) ((:|_id| . "someid") (:|_rev| . "4275808446") (:SIZE . "large") (:COLOR . "green") - (:|_rev|S_INFO - ((:|rev| . "4275808446") (:STATUS . "disk")) - ((:|rev| . "3181950830") (:STATUS . "disk")))) -;; Since the first revision is still available (:status . "disk") we -;; can still retrieve it + (:|_revs_info| + ((:|rev| . "4275808446") (:|status| . "disk")) + ((:|rev| . "3181950830") (:|status| . "disk")))) +;; Since the first revision is still available (i.e., :|status| == "disk") +;; we can still retrieve it: CLOUCHDB-USER> (get-document "someid" :revision "3181950830") ((:|_id| . "someid") (:|_rev| . "3181950830") (:SIZE . "large") (:COLOR . "blue")) @@ -317,11 +317,11 @@ (:tags . ("country" "European")) ;; Field using map property value: (:demographics . ((:population . 10230000) - ;; A nested map property: - (:religion . ((:agnostic . 0.59) - (:roman-catholic . 0.26) - (:protestant . 2.5))) - (:political-system . "democracy")))) + ;; A nested map property: + (:religion . ((:agnostic . 0.59) + (:roman-catholic . 0.26) + (:protestant . 2.5))) + (:political-system . "democracy")))) :id "czechrepublic") ((:|ok| . T) (:|id| . "czechrepublic") (:|rev| . "4272625130")) ;; Let's see what this document looks like (formatted for legibility) @@ -336,12 +336,12 @@ ((:TOTAL_ROWS . 3) (:OFFSET . 0) (:ROWS ((:|id| . "C731D3A3698DA144FB35EDA9737917F2") (:KEY . "C731D3A3698DA144FB35EDA9737917F2") - (:VALUE (:|rev| . "3363852140"))) - ((:|id| . "czechrepublic") (:KEY . "czechrepublic") (:VALUE (:|rev| . "4272625130"))) - ((:|id| . "someid") (:KEY . "someid") (:VALUE (:|rev| . "4275808446"))))) + (:|value| (:|rev| . "3363852140"))) + ((:|id| . "czechrepublic") (:KEY . "czechrepublic") (:|value| (:|rev| . "4272625130"))) + ((:|id| . "someid") (:KEY . "someid") (:|value| (:|rev| . "4275808446"))))) -
Demonstrating:
+ Note that this function does not represent any CouchDb API, nor does + it communicate with the database other than when functions are used + in the query and these functions communicate with the database. +
function | - The function should accept a single parameter, which will - contain the value of the previous match or the initial document - if the function is the first element in the query list. Query - operators following the function are applied to the result of - the function or, if the function is the last operator in the - query, the function return value is collected in the - query-document results list. + The function should accept a single parameter. This parameter + will contain the value matched by the previous query term, or + the initial document if the function is the first element in + the query list. Query operators following the function are + applied to the result of the function or, if the function is + the last operator in the query, the function return value is + collected in the query-document results list. |
- Views are the mechanism with which documents are queried in - CouchDb. There are two types of views in CouchDb: ad hoc and - persistent. As you might expect, persistent views are stored in the - database. Ad hoc views are not, they are sent from the client each - time they're used. Native CouchDb views are expressed in JavaScript - though it is not necessary to use JavaScript directly thanks - to Parenscript. + Views are the query mechanism for CouchDb. There are two types of + views in CouchDb: ad hoc and persistent. As you might expect + persistent views are stored in the database. Ad hoc views are not, + they are sent from the client each time they're used. Native CouchDb + views are expressed in JavaScript. While it is possible to use + JavaScript with the Clouchdb API, it may be more natural to use the + Parenscript library + instead. Parenscript is library for generating JavaScript using Lisp + syntax. +
++ Note that CouchDb and JavaScript are case sensitivie. Field names in + documents created using un-quoted keyword symbol field names (e.g., + :name) will be converted to upper case by Lisp and result in upper + case field names in CouchDb and JavaScript. +
++
Clouchdb | +Parenscript | +CouchDb/JavaScript | +
---|---|---|
:name, :NAME, :NaMe | +*name*, *NAME* *NaMe* | +NAME | +
:|name| | +name | +name | +
:|mixedCase| | +mixed-case | +mixedCase | +
@@ -1051,12 +1129,11 @@
Keyword parameters
-(create-document '((:name . "Laraby"))) -(ad-hoc-view "function(doc) { if (doc.name == 'Laraby') { map(null,doc.name) } }") +(ad-hoc-view "function(doc) { if (doc.NAME == 'Laraby') { map(null,doc.NAME) } }")
@@ -1103,8 +1180,8 @@
(create-document '((:name . "Laraby"))) (ad-hoc-view (ps (lambda (doc) - (with-slots (name) doc - (if (eql name "Laraby") + (with-slots (*name*) doc + (if (eql *name* "Laraby") (map nil doc))))))
@@ -1119,17 +1196,20 @@
(ad-hoc-view (ps (lambda (doc) - (if (eql doc.name "Laraby") + (if (eql doc.*name* "Laraby") (map nil doc))))))-
See (create-view)
+See (create-view) and Example 3
[Function]
create-view {view-definition}*
@@ -1234,7 +1316,10 @@ (invoke-view "names" "name" :key "Laraby")-Creates a view document containing one or more view definitions + Creates a view document containing one or more view definitions. The + view definitions may be specified in a JavaScript string + or Parenscript + s-expresions.
Example: @@ -1149,6 +1229,8 @@
See (invoke-view) +(ad-hoc-view) +and Example 3
-See (create-view) (ad-hoc-view)
+See (create-view) +(ad-hoc-view) +and Example 3 + --- /project/clouchdb/cvsroot/clouchdb/public_html/style.css 2007/12/01 14:19:59 1.1.1.1 +++ /project/clouchdb/cvsroot/clouchdb/public_html/style.css 2008/03/01 19:19:16 1.2 @@ -33,6 +33,7 @@ padding: 7px; background-color: #DDFFEE; border: 1px solid #99CCBB; + font-size: 1.2em; } p.def { From peddy at common-lisp.net Sat Mar 1 19:19:18 2008 From: peddy at common-lisp.net (peddy) Date: Sat, 1 Mar 2008 14:19:18 -0500 (EST) Subject: [clouchdb-cvs] CVS clouchdb/src Message-ID: <20080301191918.C6EFE7E02E@common-lisp.net> Update of /project/clouchdb/cvsroot/clouchdb/src In directory clnet:/tmp/cvs-serv28981/src Modified Files: changelog.txt clouchdb.lisp tests.lisp Log Message: - Updated docs with complex view key info - Updated examples with complex view examples --- /project/clouchdb/cvsroot/clouchdb/src/changelog.txt 2008/01/19 20:18:57 1.7 +++ /project/clouchdb/cvsroot/clouchdb/src/changelog.txt 2008/03/01 19:19:17 1.8 @@ -1,4 +1,12 @@ +0.0.9: + + - View functions now work with complex key types, e.g. + (invoke-view "foo" "bar" :key '("kipple" "bark")) + - Updated docs to reflect change described above + - Fixed other doc inaccuracies having to do with cl-json/case + encoding related changes. + 0.0.8: - Function set-document-property now operates non-destructively, be --- /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2008/02/22 01:33:49 1.22 +++ /project/clouchdb/cvsroot/clouchdb/src/clouchdb.lisp 2008/03/01 19:19:17 1.23 @@ -25,7 +25,7 @@ (in-package :clouchdb) (defvar *host* "localhost" "CouchDb server host name") -(defvar *port* "5984" +(defvar *port* "5984" "As of version 7.2, the IANA assigned CouchDb port (was 8888)") (defvar *db-name* "default" "Default database name") (defvar *protocol* "http" "http or https") --- /project/clouchdb/cvsroot/clouchdb/src/tests.lisp 2008/01/19 20:18:57 1.11 +++ /project/clouchdb/cvsroot/clouchdb/src/tests.lisp 2008/03/01 19:19:17 1.12 @@ -655,6 +655,42 @@ :|rows| (invoke-view "friend" "fname" :key "claire"))) (length (contains-property *people* :friends :pval "claire")))) + +(addtest (clouchdb-view-tests) + (:documentation "Create a view and see if it can be queried with a complex key") + create-view-keyquery-test2 + (ensure + (document-property :|ok| + (create-view "views" + (cons "view" + (ps (lambda (doc) + (with-slots (*city* *friends*) doc + (dolist (friend *friends*) + (map (list *city* friend) doc))))))))) + (ensure-same 1 + (length (document-property + :|rows| + (invoke-view "views" "view" :key '("boston" "charles")))))) + +(addtest (clouchdb-view-tests) + (:documentation "Create a view and see if it can be queried with a complex start and end key") + create-view-keyquery-test3 + (ensure + (document-property :|ok| + (create-view "views" + (cons "view" + (ps (lambda (doc) + (with-slots (*city* *friends*) doc + (dolist (friend *friends*) + (map (list *city* friend) doc))))))))) + (ensure-same 1 + (length (document-property + :|rows| + (invoke-view "views" + "view" + :start-key '("boston" "c") + :end-key '("boston" "d")))))) + ;; ;; ;; From peddy at common-lisp.net Sat Mar 1 19:46:03 2008 From: peddy at common-lisp.net (peddy) Date: Sat, 1 Mar 2008 14:46:03 -0500 (EST) Subject: [clouchdb-cvs] CVS clouchdb/public_html Message-ID: <20080301194603.79B39711A0@common-lisp.net> Update of /project/clouchdb/cvsroot/clouchdb/public_html In directory clnet:/tmp/cvs-serv18318 Modified Files: index.html Log Message: fixed some invalid HTML --- /project/clouchdb/cvsroot/clouchdb/public_html/index.html 2008/03/01 19:19:16 1.17 +++ /project/clouchdb/cvsroot/clouchdb/public_html/index.html 2008/03/01 19:46:03 1.18 @@ -50,6 +50,13 @@-
Clouchdb | @@ -1104,7 +1111,7 @@mixedCase |
---|
Please refer