[clouchdb-cvs] CVS clouchdb/src

peddy peddy at common-lisp.net
Sat Jun 14 21:31:35 UTC 2008


Update of /project/clouchdb/cvsroot/clouchdb/src
In directory clnet:/tmp/cvs-serv27847/src

Modified Files:
	tests.lisp package.lisp examples.lisp encoder.lisp 
Log Message:
Updated view functions for CouchDb 8.0+ views


--- /project/clouchdb/cvsroot/clouchdb/src/tests.lisp	2008/03/01 19:19:17	1.12
+++ /project/clouchdb/cvsroot/clouchdb/src/tests.lisp	2008/06/14 21:31:35	1.13
@@ -558,10 +558,11 @@
 	       (document-property
 		:|total_rows|
 		(ad-hoc-view 
-		 (ps (lambda (doc) 
-                       (with-slots (*NAME*) doc
-                         (if (= *NAME* "marc")
-			   (map null *NAME*)))))))))
+		 (ps-view () 
+                   (defun map (doc)
+                     (with-slots (*NAME*) doc
+                       (if (= *NAME* "marc")
+                           (emit null *NAME*)))))))))
 
 (addtest (clouchdb-view-tests)
   (:documentation "Create an ad-hock view that should return no results")
@@ -569,22 +570,24 @@
   (ensure-same 0 (document-property
 		  :|total_rows|
 		  (ad-hoc-view 
-		   (ps (lambda (doc) 
-			 (if (= doc.name "marie")
-			     (map null doc.name))))))))
+		   (ps-view () 
+                     (defun map (doc)
+                       (if (= doc.name "marie")
+                           (emit null doc.name))))))))
 
 (addtest (clouchdb-view-tests)
   (:documentation "Ensure a view can be created")
   create-view-test1
   (ensure 
-   (document-property :|ok|
-		      (create-view "friend"
-				   (cons "marie-view"
-					 (ps (lambda (doc)
-					       (with-slots (*friends*) doc
-						 (dolist (friend *friends*)
-						   (if (= friend "marie")
-						       (map null doc)))))))))))
+   (document-property 
+    :|ok|
+    (create-ps-view "friend"
+                    (ps-view ("marie-view")
+                      (defun map (doc)
+                        (with-slots (*friends*) doc
+                          (dolist (friend *friends*)
+                            (if (= friend "marie")
+                                (emit null doc))))))))))
 
 (addtest (clouchdb-view-tests)
   (:documentation "Ensure a view can be created and deleted")
@@ -593,13 +596,13 @@
    (document-property
     :|ok|
     (create-view "friend"
-		 (cons "marie-view"
-		       (ps (lambda (doc)
-			     (with-slots (friends) doc
-			       (dolist (friend friends)
-				 (if (= friend "marie")
-				     (map null doc))))))))))
-  (ensure (document-property :|ok| (delete-view "friend"))))
+                 (ps-view ("marie-view")
+                   (defun map (doc)
+                     (with-slots (friends) doc
+                       (dolist (friend friends)
+                         (if (= friend "marie")
+                             (emit null doc)))))))))
+   (ensure (document-property :|ok| (delete-view "friend"))))
 			     
 (addtest (clouchdb-view-tests)
   (:documentation "Creating a view that already exists should report an error")
@@ -607,36 +610,37 @@
   (ensure 
    (document-property
     :|ok|
-    (create-view "friend"
-		 (cons "marie-view"
-		       (ps (lambda (doc)
-			     (with-slots (*friends*) doc
-			       (dolist (friend *friends*)
-				 (if (= friend "marie")
-				     (map null doc))))))))))
+    (create-ps-view "friend"
+                    (ps-view ("marie-view")
+                      (defun map (doc)
+                        (with-slots (*friends*) doc
+                          (dolist (friend *friends*)
+                            (if (= friend "marie")
+                                (emit null doc)))))))))
   (ensure-same "conflict"
 	       (document-property
 		:|error|
-		(create-view "friend"
-			     (cons "marie-view"
-				   (ps (lambda (doc)
-					 (with-slots (*friends*) doc
-					   (dolist (friend *friends*)
-					     (if (= friend "marie")
-						 (map null doc)))))))))))
+		(create-ps-view "friend"
+                                (ps-view ("marie-view")
+                                  (defun map (doc)
+                                    (with-slots (*friends*) doc
+                                      (dolist (friend *friends*)
+                                        (if (= friend "marie")
+                                            (emit null doc))))))))))
 
 (addtest (clouchdb-view-tests)
   (:documentation "Create a view and see if it can be queried")
   create-view-query-test1
   (ensure 
-   (document-property :|ok|
-		      (create-view "friend"
-				   (cons "marie-view"
-					 (ps (lambda (doc)
-					       (with-slots (*friends*) doc
-						 (dolist (friend *friends*)
-						   (if (= friend "marie")
-						       (map null doc))))))))))
+   (document-property 
+    :|ok|
+    (create-ps-view "friend"
+                    (ps-view ("marie-view")
+                      (defun map (doc)
+                        (with-slots (*friends*) doc
+                          (dolist (friend *friends*)
+                            (if (= friend "marie")
+                                (emit null doc)))))))))
   (ensure-same (document-property :|total_rows| (invoke-view "friend" "marie-view"))
  	       (length (contains-property *people* :friends :pval "marie"))))
 
@@ -644,29 +648,30 @@
   (:documentation "Create a view and see if it can be queried with a key")
   create-view-keyquery-test1
   (ensure 
-   (document-property :|ok|
-		      (create-view "friend"
-				   (cons "fname"
-					 (ps (lambda (doc)
-					       (with-slots (*friends*) doc
-						 (dolist (friend *friends*)
-						   (map friend doc)))))))))
+   (document-property 
+    :|ok|
+    (create-ps-view "friend"
+                    (ps-view ("fname")
+                      (defun map (doc)
+                        (with-slots (*friends*) doc
+                          (dolist (friend *friends*)
+                            (emit friend doc))))))))
   (ensure-same (length (document-property 
 			:|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)))))))))
+   (document-property 
+    :|ok|
+    (create-ps-view "views" 
+                    (ps-view ("view")
+                      (defun map (doc)
+                        (with-slots (*city* *friends*) doc
+                          (dolist (friend *friends*)
+                            (emit (list *city* friend) doc))))))))
    (ensure-same 1 
                 (length (document-property 
                          :|rows| 
@@ -676,13 +681,14 @@
   (: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)))))))))
+   (document-property 
+    :|ok|
+    (create-ps-view "views" 
+                    (ps-view ("view")
+                      (defun map (doc)
+                        (with-slots (*city* *friends*) doc
+                          (dolist (friend *friends*)
+                            (emit (list *city* friend) doc))))))))
    (ensure-same 1 
                 (length (document-property 
                          :|rows| 
--- /project/clouchdb/cvsroot/clouchdb/src/package.lisp	2008/01/19 20:18:57	1.7
+++ /project/clouchdb/cvsroot/clouchdb/src/package.lisp	2008/06/14 21:31:35	1.8
@@ -25,7 +25,7 @@
 (cl:in-package :cl-user)
 
 (defpackage :clouchdb
-  (:use :cl :drakma :flexi-streams :s-base64)
+  (:use :cl :drakma :flexi-streams :s-base64 :parenscript)
   (:export :*scheme*
 	   :*host*
 	   :*port*
@@ -67,6 +67,8 @@
 	   :bulk-document-update
 	   :delete-document
 	   :create-view
+	   :create-ps-view
+	   :ps-view
 	   :delete-view
 	   :invoke-view
 	   :ad-hoc-view))
--- /project/clouchdb/cvsroot/clouchdb/src/examples.lisp	2008/02/16 19:36:07	1.7
+++ /project/clouchdb/cvsroot/clouchdb/src/examples.lisp	2008/06/14 21:31:35	1.8
@@ -109,17 +109,17 @@
     ;; tags. Views can also be queried with a browser at:
     ;; http://<host>:<port>/_view/<document-id>/<view-name>?key="<value>"
     ;; and edited in the HTML UI as a normal document.
-    (create-view
+    (create-ps-view
      ;; The view's document ID (views are just special documents):
      "tags"
-     (cons "tag" ; <-- the view name
-	   ;; The view definition, created in a pleasingly lispy way
-	   ;; with the lovely parenscript library. (May also be
-	   ;; specified as a string):
-	   (ps (lambda (doc)
-		 (with-slots (tags) doc
-		   (dolist (tag tags)
-		     (map tag doc)))))))
+     (ps-view ("tag") ; <-- the view name
+       ;; The view definition, created in a pleasingly lispy way
+       ;; with the lovely parenscript library. (May also be
+       ;; specified as a string):
+       (defun map (doc)
+         (with-slots (tags) doc
+           (dolist (tag tags)
+             (emit tag doc))))))
     ;; Query the view defined above and print the results
     (let ((result (invoke-view "tags" "tag" :key "european")))
       (format t "found: ~S documents:~%" (length (document-property :|rows| result)))
--- /project/clouchdb/cvsroot/clouchdb/src/encoder.lisp	2008/01/19 20:18:57	1.7
+++ /project/clouchdb/cvsroot/clouchdb/src/encoder.lisp	2008/06/14 21:31:35	1.8
@@ -76,7 +76,7 @@
   (and (listp e) (keywordp (car e))))
 
 (defun assoclp (e)
-  "Return true if parameter is, or really looks like, an associative
+  "Return true if expression is, or really looks like, an associative
 list. Dead giveaways include cons elements in the list that begin with
 a keyword. Returns the element that produced a positive result, or
 nil."




More information about the clouchdb-cvs mailing list